1 /* Hacky parallelism; Ian Jackson */
22 typedef enum { hp_idle
, hp_compute
, hp_deferring
, hp_fail
} HPState
;
27 static void checkchild(void)
33 r
= waitpid(child
,&status
,WNOHANG
); if (!r
) return;
35 Message(M_ERR
,"hacky_par: waitpid: %s\n",strerror(errno
));
40 if (WIFSIGNALED(status
)) {
41 Message(M_ERR
,"hacky_par: signaled! %s\n",strsignal(WTERMSIG(status
)));
42 } else if (!WIFEXITED(status
)) {
43 Message(M_ERR
,"hacky_par: unexpected status! %d\n", r
);
47 static HPState
start(void)
53 Message(M_ERR
,"hacky_par: fork failed: %s\n",strerror(errno
));
57 if (!child
) { /* we are the child */
62 Message(M_INFO
,"hacky_par: started, punting\n");
66 int hacky_par_start_failnow(void)
72 Message(M_INFO
,"hacky_par: busy, punting\n");
78 int hacky_par_mid_failnow(void)
81 return state
!= hp_compute
;
84 bool_t (*packy_par_gen
)(struct site
*st
);
86 void hacky_par_end(int *ok
,
87 int32_t retries
, int32_t timeout
,
88 bool_t (*send_msg
)(struct site
*st
), struct site
*st
)
104 Message(M_ERR
,"hacky_par: compute failed\n");
107 Message(M_INFO
,"hacky_par: got result, sending\n");
108 for (i
=1; i
<retries
; i
++) {
109 sleep((timeout
+ 999)/1000);
111 Message(M_ERR
,"hacky_par: retry failed\n");
119 #else /*!HACKY_PARALLEL*/
121 int hacky_par_start_failnow(void) { return 0; }
122 int hacky_par_mid_failnow(void) { return 0; }
123 void hacky_par_end(int *ok
,
124 int32_t retries
, int32_t timeout
,
125 bool_t (*send_msg
)(struct site
*st
), struct site
*st
) { }
127 #endif /*HACKY_PARALLEL...else*/