Remove the old workio command queue thread, replacing it with a kill conditional to exit the program.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
diff --git a/cgminer.c b/cgminer.c
index aafc4ef..e02caa9 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -63,7 +63,6 @@
#endif
struct workio_cmd {
- struct thr_info *thr;
struct work *work;
struct pool *pool;
};
@@ -184,6 +183,9 @@ static pthread_cond_t lp_cond;
pthread_mutex_t restart_lock;
pthread_cond_t restart_cond;
+pthread_mutex_t kill_lock;
+pthread_cond_t kill_cond;
+
double total_mhashes_done;
static struct timeval total_tv_start, total_tv_end;
@@ -2725,15 +2727,6 @@ static bool get_upstream_work(struct work *work, CURL *curl)
return rc;
}
-static void workio_cmd_free(struct workio_cmd *wc)
-{
- if (!wc)
- return;
-
- memset(wc, 0, sizeof(*wc)); /* poison */
- free(wc);
-}
-
#ifdef HAVE_CURSES
static void disable_curses(void)
{
@@ -2812,6 +2805,11 @@ static void __kill_work(void)
applog(LOG_DEBUG, "Killing off API thread");
thr = &thr_info[api_thr_id];
thr_info_cancel(thr);
+
+ applog(LOG_DEBUG, "Sending kill broadcast");
+ mutex_lock(&kill_lock);
+ pthread_cond_signal(&kill_cond);
+ mutex_unlock(&kill_lock);
}
/* This should be the common exit path */
@@ -3191,7 +3189,7 @@ retry:
}
out:
- workio_cmd_free(wc);
+ free(wc);
if (ce)
push_curl_entry(ce, pool);
return NULL;
@@ -4409,35 +4407,6 @@ static void *input_thread(void __maybe_unused *userdata)
}
#endif
-/* This thread should not be shut down unless a problem occurs */
-static void *workio_thread(void *userdata)
-{
- struct thr_info *mythr = userdata;
- bool ok = true;
-
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
-
- RenameThread("work_io");
-
- while (ok) {
- struct workio_cmd *wc;
-
- applog(LOG_DEBUG, "Popping work to work thread");
-
- /* wait for workio_cmd sent to us, on our queue */
- wc = tq_pop(mythr->q, NULL);
- if (unlikely(!wc)) {
- applog(LOG_ERR, "Failed to tq_pop in workio_thread");
- ok = false;
- break;
- }
- }
-
- tq_freeze(mythr->q);
-
- return NULL;
-}
-
static void *api_thread(void *userdata)
{
struct thr_info *mythr = userdata;
@@ -6616,6 +6585,10 @@ int main(int argc, char *argv[])
if (unlikely(pthread_cond_init(&restart_cond, NULL)))
quit(1, "Failed to pthread_cond_init restart_cond");
+ mutex_init(&kill_lock);
+ if (unlikely(pthread_cond_init(&kill_cond, NULL)))
+ quit(1, "Failed to pthread_cond_init kill_cond");
+
sprintf(packagename, "%s %s", PACKAGE, VERSION);
#ifdef WANT_CPUMINE
@@ -6901,10 +6874,6 @@ int main(int argc, char *argv[])
if (!thr->q)
quit(1, "Failed to tq_new");
- /* start work I/O thread */
- if (thr_info_create(thr, NULL, workio_thread, thr))
- quit(1, "workio thread create failed");
-
stage_thr_id = mining_threads + 1;
thr = &thr_info[stage_thr_id];
thr->q = tq_new();
@@ -7086,10 +7055,11 @@ begin_bench:
for (i = 0; i < mining_threads + opt_queue; i++)
queue_request();
- /* main loop - simply wait for workio thread to exit. This is not the
- * normal exit path and only occurs should the workio_thread die
- * unexpectedly */
- pthread_join(thr_info[work_thr_id].pth, NULL);
+ /* Wait till we receive the conditional telling us to die */
+ mutex_lock(&kill_lock);
+ pthread_cond_wait(&kill_cond, &kill_lock);
+ mutex_unlock(&kill_lock);
+
applog(LOG_INFO, "workio thread dead, exiting.");
clean_up();