From 5b25f89d00433f1c11576d1ea19304797dc60d1b Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 31 Oct 2026 18:48:00 +0100 Subject: Refactor ot_workqueue out of ot_mutex, no behaviour change --- ot_fullscrape.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'ot_fullscrape.c') diff --git a/ot_fullscrape.c b/ot_fullscrape.c index a86d6d7..ae29308 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c @@ -23,6 +23,7 @@ #include "ot_fullscrape.h" #include "ot_iovec.h" #include "ot_mutex.h" +#include "ot_workqueue.h" #include "ot_urlencoded.h" #include "trackerlogic.h" @@ -54,7 +55,7 @@ static void *fullscrape_worker(void *args) { while (g_opentracker_running) { ot_tasktype tasktype = TASK_FULLSCRAPE; - ot_taskid taskid = mutex_workqueue_poptask(&tasktype); + ot_taskid taskid = workqueue_poptask(&tasktype); if (!taskid) break; #ifdef WANT_COMPRESSION_ZSTD @@ -68,7 +69,7 @@ static void *fullscrape_worker(void *args) { else #endif fullscrape_make(taskid, tasktype); - mutex_workqueue_pushchunked(taskid, NULL); + workqueue_pushchunked(taskid, NULL); } return NULL; } @@ -79,12 +80,12 @@ void fullscrape_init(void) { } void fullscrape_deinit(void) { - mutex_workqueue_wakeall(); + workqueue_wakeall(); pthread_join( thread_id, NULL ); } void fullscrape_deliver( int64_t sock, ot_tasktype tasktype ) { - mutex_workqueue_pushtask( sock, TASK_FULLSCRAPE | tasktype ); + workqueue_pushtask( sock, TASK_FULLSCRAPE | tasktype ); } static void fullscrape_write_one( ot_tasktype mode, char **cursor, ot_torrent *torrent, ot_hash *hash ) { @@ -170,7 +171,7 @@ static void fullscrape_make(int taskid, ot_tasktype mode) { if (r > re) { iovector.iov_len = r - (char *)iovector.iov_base; - if (mutex_workqueue_pushchunked(taskid, &iovector)) { + if (workqueue_pushchunked(taskid, &iovector)) { free(iovector.iov_base); mutex_bucket_unlock(bucket, 0); return; @@ -200,7 +201,7 @@ static void fullscrape_make(int taskid, ot_tasktype mode) { /* Send rest of data */ iovector.iov_len = r - (char *)iovector.iov_base; - if (mutex_workqueue_pushchunked(taskid, &iovector)) + if (workqueue_pushchunked(taskid, &iovector)) free(iovector.iov_base); } @@ -251,7 +252,7 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { while (!strm.avail_out) { iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base; - if (mutex_workqueue_pushchunked(taskid, &iovector)) { + if (workqueue_pushchunked(taskid, &iovector)) { free(iovector.iov_base); mutex_bucket_unlock(bucket, 0); return; @@ -291,7 +292,7 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { fprintf(stderr, "deflate() failed while in fullscrape_make()'s endgame.\n"); iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base; - if (mutex_workqueue_pushchunked(taskid, &iovector)) { + if (workqueue_pushchunked(taskid, &iovector)) { free(iovector.iov_base); deflateEnd(&strm); return; @@ -314,7 +315,7 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { /* Only pass the new buffer if there actually was some data left in the buffer */ iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base; - if (!iovector.iov_len || mutex_workqueue_pushchunked(taskid, &iovector)) + if (!iovector.iov_len || workqueue_pushchunked(taskid, &iovector)) free(iovector.iov_base); } @@ -380,7 +381,7 @@ static void fullscrape_make_zstd(int taskid, ot_tasktype mode) { while (outbuf.pos + OT_SCRAPE_MAXENTRYLEN > outbuf.size) { iovector.iov_len = outbuf.size; - if (mutex_workqueue_pushchunked(taskid, &iovector)) { + if (workqueue_pushchunked(taskid, &iovector)) { free(iovector.iov_base); ZSTD_freeCCtx(zstream); return mutex_bucket_unlock(bucket, 0); @@ -418,7 +419,7 @@ static void fullscrape_make_zstd(int taskid, ot_tasktype mode) { more_bytes = ZSTD_compressStream2(zstream, &outbuf, &inbuf, ZSTD_e_end); iovector.iov_len = outbuf.pos; - if (mutex_workqueue_pushchunked(taskid, &iovector)) { + if (workqueue_pushchunked(taskid, &iovector)) { free(iovector.iov_base); ZSTD_freeCCtx(zstream); return; @@ -443,7 +444,7 @@ static void fullscrape_make_zstd(int taskid, ot_tasktype mode) { /* Only pass the new buffer if there actually was some data left in the buffer */ iovector.iov_len = outbuf.pos; - if (!iovector.iov_len || mutex_workqueue_pushchunked(taskid, &iovector)) + if (!iovector.iov_len || workqueue_pushchunked(taskid, &iovector)) free(iovector.iov_base); } -- cgit v1.3