1 /* Hacky parallelism */
3 * This file is part of secnet.
4 * See README for full list of copyright holders.
6 * secnet is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * secnet is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * version 3 along with secnet; if not, see
18 * https://www.gnu.org/licenses/gpl.html.
40 typedef enum { hp_idle, hp_compute, hp_deferring, hp_fail } HPState;
45 static void checkchild(void)
51 r= waitpid(child,&status,WNOHANG); if (!r) return;
53 Message(M_ERR,"hacky_par: waitpid: %s\n",strerror(errno));
58 if (WIFSIGNALED(status)) {
59 Message(M_ERR,"hacky_par: signaled! %s\n",strsignal(WTERMSIG(status)));
60 } else if (!WIFEXITED(status)) {
61 Message(M_ERR,"hacky_par: unexpected status! %d\n", r);
65 static HPState start(void)
71 Message(M_ERR,"hacky_par: fork failed: %s\n",strerror(errno));
75 if (!child) { /* we are the child */
80 Message(M_INFO,"hacky_par: started, punting\n");
84 int hacky_par_start_failnow(void)
90 Message(M_INFO,"hacky_par: busy, punting\n");
96 int hacky_par_mid_failnow(void)
99 return state != hp_compute;
102 bool_t (*packy_par_gen)(struct site *st);
104 void hacky_par_end(int *ok,
105 int32_t retries, int32_t timeout,
106 bool_t (*send_msg)(struct site *st), struct site *st)
122 Message(M_ERR,"hacky_par: compute failed\n");
125 Message(M_INFO,"hacky_par: got result, sending\n");
126 for (i=1; i<retries; i++) {
127 sleep((timeout + 999)/1000);
129 Message(M_ERR,"hacky_par: retry failed\n");
137 #else /*!HACKY_PARALLEL*/
139 int hacky_par_start_failnow(void) { return 0; }
140 int hacky_par_mid_failnow(void) { return 0; }
141 void hacky_par_end(int *ok,
142 int32_t retries, int32_t timeout,
143 bool_t (*send_msg)(struct site *st), struct site *st) { }
145 #endif /*HACKY_PARALLEL...else*/