diff options
Diffstat (limited to 'child.c')
-rw-r--r-- | child.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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 = { |