1 /* Hacky parallelism; Ian Jackson */
22 typedef enum { hp_idle, hp_compute, hp_deferring, hp_fail } HPState;
27 static void checkchild(void) {
32 r= waitpid(child,&status,WNOHANG); if (!r) return;
34 Message(M_ERR,"hacky_par: waitpid: %s\n",strerror(errno));
39 if (WIFSIGNALED(status)) {
40 Message(M_ERR,"hacky_par: signaled! %s\n",strsignal(WTERMSIG(status)));
41 } else if (!WIFEXITED(status)) {
42 Message(M_ERR,"hacky_par: unexpected status! %d\n", r);
46 static HPState start(void) {
51 Message(M_ERR,"hacky_par: fork failed: %s\n",strerror(errno));
55 if (!child) { /* we are the child */
59 Message(M_INFO,"hacky_par: started, punting\n");
63 int hacky_par_start_failnow(void) {
68 Message(M_INFO,"hacky_par: busy, punting\n");
74 int hacky_par_mid_failnow(void) {
76 return state != hp_compute;
79 bool_t (*packy_par_gen)(struct site *st);
81 void hacky_par_end(int *ok,
82 int32_t retries, int32_t timeout,
83 bool_t (*send_msg)(struct site *st), struct site *st) {
98 Message(M_ERR,"hacky_par: compute failed\n");
101 Message(M_INFO,"hacky_par: got result, sending\n");
102 for (i=1; i<retries; i++) {
103 sleep((timeout + 999)/1000);
105 Message(M_ERR,"hacky_par: retry failed\n");
113 #else /*!HACKY_PARALLEL*/
115 int hacky_par_start_failnow(void) { return 0; }
116 int hacky_par_mid_failnow(void) { return 0; }
117 void hacky_par_end(int *ok,
118 int32_t retries, int32_t timeout,
119 bool_t (*send_msg)(struct site *st), struct site *st) { }
121 #endif /*HACKY_PARALLEL...else*/