diff options
author | Sergey Nazaryev <sergey@nazaryev.ru> | 2016-04-24 16:11:08 +0000 |
---|---|---|
committer | Sergey Nazaryev <sergey@nazaryev.ru> | 2016-04-24 16:11:08 +0000 |
commit | a100fc191af0babcea7e702fa910abd76b233de9 (patch) | |
tree | f97f95a0ca5038d338e3724eaf2b3500e4f62973 | |
parent | 19a5db6c6a50c61938976b02f625fd1bdcd5118e (diff) | |
download | pa4-a100fc191af0babcea7e702fa910abd76b233de9.zip pa4-a100fc191af0babcea7e702fa910abd76b233de9.tar.gz pa4-a100fc191af0babcea7e702fa910abd76b233de9.tar.bz2 |
Fixed clang warning; added first column with initial balances; clang instead of gcc
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | child.c | 18 |
2 files changed, 13 insertions, 9 deletions
@@ -1,5 +1,5 @@ -CFLAGS = -std=c99 -Wall -Wpedantic -CC = gcc +CFLAGS = -std=c99 -Wall -pedantic +CC = clang all: pa2 @@ -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 = { |