diff options
Diffstat (limited to 'child.c')
-rw-r--r-- | child.c | 88 |
1 files changed, 88 insertions, 0 deletions
@@ -0,0 +1,88 @@ +#include <stdint.h> + +#include "main.h" +#include "ipc.h" + +void child_phase0( dist_info_t *info, uint8_t id ) { + close_redundant_pipes( info, id ); +} + +void child_phase1( dist_info_t *info, uint8_t id ) { + uint8_t receive_cnt; + Message msg; + + my_info_t me = { + .id = id, + .dist_info = info + }; + + Message start_msg = { + .s_header = { + .s_magic = MESSAGE_MAGIC, + .s_payload_len = 0, + .s_type = STARTED, + .s_local_time = 0 + } + }; + + send_multicast(&me, &start_msg); + + receive_cnt = info->x; + while( receive_cnt ) { + if( !receive_any( &me, &msg ) ) { + if( msg.s_header.s_type != STARTED ) + _exit(1); + + receive_cnt--; + } + } +} + +void child_phase2( dist_info_t *info, uint8_t id ) { +} + +void child_phase3( dist_info_t *info, uint8_t id ) { + uint8_t receive_cnt; + Message msg; + + my_info_t me = { + .id = id, + .dist_info = info + }; + + Message done_msg = { + .s_header = { + .s_magic = MESSAGE_MAGIC, + .s_payload_len = 0, + .s_type = DONE, + .s_local_time = 0 + } + }; + + send_multicast(&me, &done_msg); + receive_cnt = info->x; + while( receive_cnt ) { + if( !receive_any( &me, &msg ) ) { + if( msg.s_header.s_type != DONE ) + _exit(1); + + receive_cnt--; + } + } +} + +void child_workflow( dist_info_t *info, uint8_t id ) { + /* CHILD PHASE 0: Close all redundant descriptors */ + child_phase0(info, id); + + /* CHILD PHASE 1: Send STARTED message for all, receive STARTED + * messages from other childs */ + child_phase1(info, id); + + /* CHILD PHASE 2: Do some useful work */ + child_phase2(info, id); + + /* CHILD PHASE 3: Send DONE message for all, receive DONE messages from + * other childs and exit */ + child_phase3(info, id); +} |