Change pth from being a pointer as we can dereference if we're unlucky on stopping longpoll.
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
diff --git a/main.c b/main.c
index b840bce..11d8b97 100644
--- a/main.c
+++ b/main.c
@@ -4549,7 +4549,7 @@ select_cgpu:
thr->rolling = thr->cgpu->rolling = 0;
/* Reports the last time we tried to revive a sick GPU */
gettimeofday(&thr->sick, NULL);
- if (thr->pth && !pthread_cancel(*thr->pth)) {
+ if (!pthread_cancel(thr->pth)) {
applog(LOG_WARNING, "Thread %d still exists, killing it off", thr_id);
} else
applog(LOG_WARNING, "Thread %d no longer exists", thr_id);
@@ -5349,7 +5349,7 @@ int main (int argc, char *argv[])
/* start stage thread */
if (thr_info_create(thr, NULL, stage_thread, thr))
quit(1, "stage thread create failed");
- pthread_detach(*thr->pth);
+ pthread_detach(thr->pth);
/* Create a unique get work queue */
getq = tq_new();
@@ -5525,7 +5525,7 @@ int main (int argc, char *argv[])
thr = &thr_info[input_thr_id];
if (thr_info_create(thr, NULL, input_thread, thr))
quit(1, "input thread create failed");
- pthread_detach(*thr->pth);
+ pthread_detach(thr->pth);
/* Create reinit cpu thread */
cpur_thr_id = mining_threads + 5;
@@ -5546,7 +5546,7 @@ int main (int argc, char *argv[])
quit(1, "reinit_gpu thread create failed");
/* main loop - simply wait for workio thread to exit */
- pthread_join(*thr_info[work_thr_id].pth, NULL);
+ pthread_join(thr_info[work_thr_id].pth, NULL);
applog(LOG_INFO, "workio thread dead, exiting.");
gettimeofday(&total_tv_end, NULL);
diff --git a/miner.h b/miner.h
index 75c53ce..d272cb2 100644
--- a/miner.h
+++ b/miner.h
@@ -225,7 +225,7 @@ struct thread_q {
struct thr_info {
int id;
- pthread_t *pth;
+ pthread_t pth;
struct thread_q *q;
struct cgpu_info *cgpu;
struct timeval last;
diff --git a/util.c b/util.c
index aca9e81..1f36450 100644
--- a/util.c
+++ b/util.c
@@ -655,21 +655,9 @@ out:
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg)
{
- int ret = -1;
-
- thr->pth = malloc(sizeof(pthread_t));
- if (unlikely(!thr->pth)) {
- applog(LOG_ERR, "Failed to malloc in thr_info_create");
- return ret;
- }
-
- ret = pthread_create(thr->pth, attr, start, arg);
- if (unlikely(ret)) {
- applog(LOG_ERR, "Failed to pthread_create in thr_info_create");
- free(thr->pth);
- thr->pth = NULL;
- }
+ int ret;
+ ret = pthread_create(&thr->pth, attr, start, arg);
return ret;
}
@@ -680,10 +668,6 @@ void thr_info_cancel(struct thr_info *thr)
if (thr->q)
tq_freeze(thr->q);
- if (thr->pth) {
- if (pthread_cancel(*thr->pth))
- pthread_join(*thr->pth, NULL);
- free(thr->pth);
- thr->pth = NULL;
- }
+ if (pthread_cancel(thr->pth))
+ pthread_join(thr->pth, NULL);
}