Use cgcompletion timeouts for the unreliable shutdown functions on kill_work.
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
diff --git a/cgminer.c b/cgminer.c
index a9c459d..159d765 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3149,6 +3149,35 @@ static void disable_curses(void)
}
#endif
+static void kill_timeout(struct thr_info *thr)
+{
+ cg_completion_timeout(&thr_info_cancel, thr, 1000);
+}
+
+static void kill_mining(void)
+{
+ struct thr_info *thr;
+ int i;
+
+ applog(LOG_DEBUG, "Killing off mining threads");
+ /* Kill the mining threads*/
+ for (i = 0; i < mining_threads; i++) {
+ pthread_t *pth = NULL;
+
+ thr = get_thread(i);
+ if (thr && PTH(thr) != 0L)
+ pth = &thr->pth;
+ thr_info_cancel(thr);
+#ifndef WIN32
+ if (pth && *pth)
+ pthread_join(*pth, NULL);
+#else
+ if (pth && pth->p)
+ pthread_join(*pth, NULL);
+#endif
+ }
+}
+
static void __kill_work(void)
{
struct thr_info *thr;
@@ -3165,19 +3194,19 @@ static void __kill_work(void)
if (!opt_scrypt) {
applog(LOG_DEBUG, "Killing off HotPlug thread");
thr = &control_thr[hotplug_thr_id];
- thr_info_cancel(thr);
+ kill_timeout(thr);
}
#endif
applog(LOG_DEBUG, "Killing off watchpool thread");
/* Kill the watchpool thread */
thr = &control_thr[watchpool_thr_id];
- thr_info_cancel(thr);
+ kill_timeout(thr);
applog(LOG_DEBUG, "Killing off watchdog thread");
/* Kill the watchdog thread */
thr = &control_thr[watchdog_thr_id];
- thr_info_cancel(thr);
+ kill_timeout(thr);
applog(LOG_DEBUG, "Shutting down mining threads");
for (i = 0; i < mining_threads; i++) {
@@ -3195,43 +3224,27 @@ static void __kill_work(void)
sleep(1);
- applog(LOG_DEBUG, "Killing off mining threads");
- /* Kill the mining threads*/
- for (i = 0; i < mining_threads; i++) {
- pthread_t *pth = NULL;
-
- thr = get_thread(i);
- if (thr && PTH(thr) != 0L)
- pth = &thr->pth;
- thr_info_cancel(thr);
-#ifndef WIN32
- if (pth && *pth)
- pthread_join(*pth, NULL);
-#else
- if (pth && pth->p)
- pthread_join(*pth, NULL);
-#endif
- }
+ cg_completion_timeout(&kill_mining, NULL, 3000);
applog(LOG_DEBUG, "Killing off stage thread");
/* Stop the others */
thr = &control_thr[stage_thr_id];
- thr_info_cancel(thr);
+ kill_timeout(thr);
applog(LOG_DEBUG, "Killing off API thread");
thr = &control_thr[api_thr_id];
- thr_info_cancel(thr);
+ kill_timeout(thr);
#ifdef USE_USBUTILS
/* Release USB resources in case it's a restart
* and not a QUIT */
if (!opt_scrypt) {
applog(LOG_DEBUG, "Releasing all USB devices");
- usb_cleanup();
+ cg_completion_timeout(&usb_cleanup, NULL, 1000);
applog(LOG_DEBUG, "Killing off usbres thread");
thr = &control_thr[usbres_thr_id];
- thr_info_cancel(thr);
+ kill_timeout(thr);
}
#endif