blob: c4742ff44a780e5b9a89e9ae763005f47fda0f36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include <stdint.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include "dist.h"
#include "ipc.h"
#include "lamport.h"
void parent_workflow( dist_info_t *info ) {
Message msg;
uint8_t i, receive_cnt;
pid_t wpid;
int status;
int ret = 0;
lamport_init( &gl_lamport_time );
my_info_t me = {
.id = PARENT_ID,
.dist_info = info
};
// PARENT PHASE 0: Close all redundant descriptors
close_redundant_pipes( info, PARENT_ID );
// PARENT PHASE 1: Receive all STARTED messages from all childs
for( i = 1; i <= info->x; i++ ) {
if( !receive( &me, i, &msg ) ) {
lamport_message_handler( &gl_lamport_time, msg.s_header.s_local_time );
if( msg.s_header.s_type != STARTED ) {
ret = 1;
break;
}
}
}
// PARENT PHASE 2: Receive all DONE messages
while( info->workers ) {
if( !receive_any( &me, &msg ) ) {
lamport_message_handler( &gl_lamport_time, msg.s_header.s_local_time );
if( msg.s_header.s_type == DONE )
info->workers--;
}
}
// PARENT PHASE 3: Wait for the end of all processes
receive_cnt = info->x;
while( receive_cnt != 0 ) {
if( (wpid = wait(&status)) > 0 ) {
receive_cnt--;
}
}
exit( ret );
}
|