summaryrefslogtreecommitdiff
path: root/ot_mutex.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-27 21:32:24 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-27 21:32:24 +0100
commit6cbd21542cf7a751e6f0f38864e7e9eae8fa3b14 (patch)
treeb5416c7e6ad2ac30cfe51559f69c122ed493450d /ot_mutex.c
parente1d7b7771e915a01b5f1dd12664a6ac7fb397dfb (diff)
Plug in the new per-thread stats counter, also make sure that the ot_clean sleep does not stall tracker exit
Diffstat (limited to 'ot_mutex.c')
-rw-r--r--ot_mutex.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/ot_mutex.c b/ot_mutex.c
index 37d9962..c44efed 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -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 */
280void 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
274void mutex_deinit(void) { 286void 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)