diff options
Diffstat (limited to 'ot_mutex.c')
| -rw-r--r-- | ot_mutex.c | 16 |
1 files changed, 14 insertions, 2 deletions
| @@ -6,6 +6,7 @@ | |||
| 6 | /* System */ | 6 | /* System */ |
| 7 | #include <arpa/inet.h> | 7 | #include <arpa/inet.h> |
| 8 | #include <pthread.h> | 8 | #include <pthread.h> |
| 9 | #include <stdatomic.h> | ||
| 9 | #include <stdio.h> | 10 | #include <stdio.h> |
| 10 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| 11 | #include <unistd.h> | 12 | #include <unistd.h> |
| @@ -145,9 +146,13 @@ ot_taskid mutex_workqueue_poptask(ot_tasktype *tasktype) { | |||
| 145 | break; | 146 | break; |
| 146 | } | 147 | } |
| 147 | 148 | ||
| 148 | /* Wait until the next task is being fed */ | 149 | /* Wait until the next task is being fed, unless the tracker is on its |
| 149 | if (!taskid) | 150 | way out, in which case the worker is meant to leave rather than wait */ |
| 151 | if (!taskid) { | ||
| 152 | if (!g_opentracker_running) | ||
| 153 | break; | ||
| 150 | pthread_cond_wait(&tasklist_being_filled, &tasklist_mutex); | 154 | pthread_cond_wait(&tasklist_being_filled, &tasklist_mutex); |
| 155 | } | ||
| 151 | } | 156 | } |
| 152 | 157 | ||
| 153 | /* Release lock */ | 158 | /* Release lock */ |
| @@ -271,6 +276,13 @@ void mutex_init(void) { | |||
| 271 | memset(all_torrents, 0, sizeof(all_torrents)); | 276 | memset(all_torrents, 0, sizeof(all_torrents)); |
| 272 | } | 277 | } |
| 273 | 278 | ||
| 279 | /* Let every worker parked on the queue see that the tracker is stopping */ | ||
| 280 | void mutex_workqueue_wakeall(void) { | ||
| 281 | pthread_mutex_lock(&tasklist_mutex); | ||
| 282 | pthread_cond_broadcast(&tasklist_being_filled); | ||
| 283 | pthread_mutex_unlock(&tasklist_mutex); | ||
| 284 | } | ||
| 285 | |||
| 274 | void mutex_deinit(void) { | 286 | void mutex_deinit(void) { |
| 275 | size_t i; | 287 | size_t i; |
| 276 | for (i = 0; i < OT_BUCKET_COUNT; ++i) | 288 | for (i = 0; i < OT_BUCKET_COUNT; ++i) |
