summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Nazaryev <sergey@nazaryev.ru>2016-04-24 16:11:08 +0000
committerSergey Nazaryev <sergey@nazaryev.ru>2016-04-24 16:11:08 +0000
commita100fc191af0babcea7e702fa910abd76b233de9 (patch)
treef97f95a0ca5038d338e3724eaf2b3500e4f62973
parent19a5db6c6a50c61938976b02f625fd1bdcd5118e (diff)
downloadpa2-a100fc191af0babcea7e702fa910abd76b233de9.zip
pa2-a100fc191af0babcea7e702fa910abd76b233de9.tar.gz
pa2-a100fc191af0babcea7e702fa910abd76b233de9.tar.bz2
Fixed clang warning; added first column with initial balances; clang instead of gccHEADmaster
-rw-r--r--Makefile4
-rw-r--r--child.c18
2 files changed, 13 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 70cefac..8e1e684 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-CFLAGS = -std=c99 -Wall -Wpedantic
-CC = gcc
+CFLAGS = -std=c99 -Wall -pedantic
+CC = clang
all: pa2
diff --git a/child.c b/child.c
index 9f2a1d9..cf7496f 100644
--- a/child.c
+++ b/child.c
@@ -69,18 +69,20 @@ void child_phase2( dist_info_t *info, uint8_t id, BalanceHistory *history ) {
};
uint8_t i;
- uint8_t last_order_time = -1;
+ uint8_t last_order_time = 0;
+
+ balanceState.s_balance = info->balances[ id ];
+ balanceState.s_time = 0;
+ balanceState.s_balance_pending_in = 0;
+ history->s_history[ last_order_time ] = balanceState;
int running = 1;
while( running ) {
if( !receive_any( &me, &msg ) ) {
switch( msg.s_header.s_type ) {
case TRANSFER: {
- if( msg.s_payload == NULL )
- return;
-
TransferOrder *order = (TransferOrder *) msg.s_payload;
- uint8_t cur_order_time = msg.s_header.s_local_time;
+ uint8_t cur_order_time = get_physical_time();
for( i = last_order_time + 1; i < cur_order_time; i++ ) {
balanceState.s_balance = info->balances[ id ];
@@ -97,6 +99,8 @@ void child_phase2( dist_info_t *info, uint8_t id, BalanceHistory *history ) {
fputs( buf, stdout );
info->balances[ id ] -= order->s_amount;
+
+ msg.s_header.s_local_time = get_physical_time();
send( &me, order->s_dst, &msg );
} else if( order->s_dst == id ) {
snprintf( buf, sizeof(buf), log_transfer_in_fmt,
@@ -180,12 +184,12 @@ void child_phase3( dist_info_t *info, uint8_t id, BalanceHistory *history ) {
fputs( buf, stdout );
int time = get_physical_time();
- for( i = history->s_history_len; i < time; i++ ) {
+ for( i = history->s_history_len; i <= time; i++ ) {
history->s_history[i].s_balance = history->s_history[ history->s_history_len - 1].s_balance;
history->s_history[i].s_time = i;
}
- history->s_history_len = time;
+ history->s_history_len = time+1;
int wr_size = history->s_history_len * sizeof(history->s_history[0]);
Message historyMsg = {