Browse Source

Exit cleanly if we abort before various threads are set up or if they no longer exist.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
bcba6f83fb
  1. 27
      main.c

27
main.c

@ -2255,25 +2255,28 @@ void kill_work(void)
/* Kill the watchdog thread */ /* Kill the watchdog thread */
thr = &thr_info[watchdog_thr_id]; thr = &thr_info[watchdog_thr_id];
if (thr->pth) if (thr && thr->pth)
pthread_cancel(*thr->pth); pthread_cancel(*thr->pth);
/* Stop the mining threads*/ /* Stop the mining threads*/
for (i = 0; i < mining_threads; i++) { for (i = 0; i < mining_threads; i++) {
thr = &thr_info[i]; thr = &thr_info[i];
if (!thr)
continue;
if (!thr->pth) if (!thr->pth)
continue; continue;
tq_freeze(thr->q); if (thr->q)
tq_freeze(thr->q);
/* No need to check if this succeeds or not */ /* No need to check if this succeeds or not */
pthread_cancel(*thr->pth); pthread_cancel(*thr->pth);
} }
/* Stop the others */ /* Stop the others */
thr = &thr_info[stage_thr_id]; thr = &thr_info[stage_thr_id];
if (thr->pth) if (thr && thr->pth)
pthread_cancel(*thr->pth); pthread_cancel(*thr->pth);
thr = &thr_info[longpoll_thr_id]; thr = &thr_info[longpoll_thr_id];
if (thr->pth) if (thr && thr->pth)
pthread_cancel(*thr->pth); pthread_cancel(*thr->pth);
wc = calloc(1, sizeof(*wc)); wc = calloc(1, sizeof(*wc));
@ -2289,14 +2292,16 @@ void kill_work(void)
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "Pushing die request to work thread"); applog(LOG_DEBUG, "Pushing die request to work thread");
if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
applog(LOG_ERR, "Failed to tq_push work in kill_work");
exit (1);
}
thr = &thr_info[work_thr_id]; thr = &thr_info[work_thr_id];
if (thr->pth) if (thr) {
pthread_cancel(*thr->pth); if (unlikely(!tq_push(thr->q, wc))) {
applog(LOG_ERR, "Failed to tq_push work in kill_work");
exit (1);
}
if (thr->pth)
pthread_cancel(*thr->pth);
}
} }
void quit(int status, const char *format, ...); void quit(int status, const char *format, ...);

Loading…
Cancel
Save