xref: /aosp_15_r20/external/zstd/lib/common/pool.c (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  * You may select, at your option, one of the above-listed licenses.
9*01826a49SYabin Cui  */
10*01826a49SYabin Cui 
11*01826a49SYabin Cui 
12*01826a49SYabin Cui /* ======   Dependencies   ======= */
13*01826a49SYabin Cui #include "../common/allocations.h"  /* ZSTD_customCalloc, ZSTD_customFree */
14*01826a49SYabin Cui #include "zstd_deps.h" /* size_t */
15*01826a49SYabin Cui #include "debug.h"     /* assert */
16*01826a49SYabin Cui #include "pool.h"
17*01826a49SYabin Cui 
18*01826a49SYabin Cui /* ======   Compiler specifics   ====== */
19*01826a49SYabin Cui #if defined(_MSC_VER)
20*01826a49SYabin Cui #  pragma warning(disable : 4204)        /* disable: C4204: non-constant aggregate initializer */
21*01826a49SYabin Cui #endif
22*01826a49SYabin Cui 
23*01826a49SYabin Cui 
24*01826a49SYabin Cui #ifdef ZSTD_MULTITHREAD
25*01826a49SYabin Cui 
26*01826a49SYabin Cui #include "threading.h"   /* pthread adaptation */
27*01826a49SYabin Cui 
28*01826a49SYabin Cui /* A job is a function and an opaque argument */
29*01826a49SYabin Cui typedef struct POOL_job_s {
30*01826a49SYabin Cui     POOL_function function;
31*01826a49SYabin Cui     void *opaque;
32*01826a49SYabin Cui } POOL_job;
33*01826a49SYabin Cui 
34*01826a49SYabin Cui struct POOL_ctx_s {
35*01826a49SYabin Cui     ZSTD_customMem customMem;
36*01826a49SYabin Cui     /* Keep track of the threads */
37*01826a49SYabin Cui     ZSTD_pthread_t* threads;
38*01826a49SYabin Cui     size_t threadCapacity;
39*01826a49SYabin Cui     size_t threadLimit;
40*01826a49SYabin Cui 
41*01826a49SYabin Cui     /* The queue is a circular buffer */
42*01826a49SYabin Cui     POOL_job *queue;
43*01826a49SYabin Cui     size_t queueHead;
44*01826a49SYabin Cui     size_t queueTail;
45*01826a49SYabin Cui     size_t queueSize;
46*01826a49SYabin Cui 
47*01826a49SYabin Cui     /* The number of threads working on jobs */
48*01826a49SYabin Cui     size_t numThreadsBusy;
49*01826a49SYabin Cui     /* Indicates if the queue is empty */
50*01826a49SYabin Cui     int queueEmpty;
51*01826a49SYabin Cui 
52*01826a49SYabin Cui     /* The mutex protects the queue */
53*01826a49SYabin Cui     ZSTD_pthread_mutex_t queueMutex;
54*01826a49SYabin Cui     /* Condition variable for pushers to wait on when the queue is full */
55*01826a49SYabin Cui     ZSTD_pthread_cond_t queuePushCond;
56*01826a49SYabin Cui     /* Condition variables for poppers to wait on when the queue is empty */
57*01826a49SYabin Cui     ZSTD_pthread_cond_t queuePopCond;
58*01826a49SYabin Cui     /* Indicates if the queue is shutting down */
59*01826a49SYabin Cui     int shutdown;
60*01826a49SYabin Cui };
61*01826a49SYabin Cui 
62*01826a49SYabin Cui /* POOL_thread() :
63*01826a49SYabin Cui  * Work thread for the thread pool.
64*01826a49SYabin Cui  * Waits for jobs and executes them.
65*01826a49SYabin Cui  * @returns : NULL on failure else non-null.
66*01826a49SYabin Cui  */
POOL_thread(void * opaque)67*01826a49SYabin Cui static void* POOL_thread(void* opaque) {
68*01826a49SYabin Cui     POOL_ctx* const ctx = (POOL_ctx*)opaque;
69*01826a49SYabin Cui     if (!ctx) { return NULL; }
70*01826a49SYabin Cui     for (;;) {
71*01826a49SYabin Cui         /* Lock the mutex and wait for a non-empty queue or until shutdown */
72*01826a49SYabin Cui         ZSTD_pthread_mutex_lock(&ctx->queueMutex);
73*01826a49SYabin Cui 
74*01826a49SYabin Cui         while ( ctx->queueEmpty
75*01826a49SYabin Cui             || (ctx->numThreadsBusy >= ctx->threadLimit) ) {
76*01826a49SYabin Cui             if (ctx->shutdown) {
77*01826a49SYabin Cui                 /* even if !queueEmpty, (possible if numThreadsBusy >= threadLimit),
78*01826a49SYabin Cui                  * a few threads will be shutdown while !queueEmpty,
79*01826a49SYabin Cui                  * but enough threads will remain active to finish the queue */
80*01826a49SYabin Cui                 ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
81*01826a49SYabin Cui                 return opaque;
82*01826a49SYabin Cui             }
83*01826a49SYabin Cui             ZSTD_pthread_cond_wait(&ctx->queuePopCond, &ctx->queueMutex);
84*01826a49SYabin Cui         }
85*01826a49SYabin Cui         /* Pop a job off the queue */
86*01826a49SYabin Cui         {   POOL_job const job = ctx->queue[ctx->queueHead];
87*01826a49SYabin Cui             ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
88*01826a49SYabin Cui             ctx->numThreadsBusy++;
89*01826a49SYabin Cui             ctx->queueEmpty = (ctx->queueHead == ctx->queueTail);
90*01826a49SYabin Cui             /* Unlock the mutex, signal a pusher, and run the job */
91*01826a49SYabin Cui             ZSTD_pthread_cond_signal(&ctx->queuePushCond);
92*01826a49SYabin Cui             ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
93*01826a49SYabin Cui 
94*01826a49SYabin Cui             job.function(job.opaque);
95*01826a49SYabin Cui 
96*01826a49SYabin Cui             /* If the intended queue size was 0, signal after finishing job */
97*01826a49SYabin Cui             ZSTD_pthread_mutex_lock(&ctx->queueMutex);
98*01826a49SYabin Cui             ctx->numThreadsBusy--;
99*01826a49SYabin Cui             ZSTD_pthread_cond_signal(&ctx->queuePushCond);
100*01826a49SYabin Cui             ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
101*01826a49SYabin Cui         }
102*01826a49SYabin Cui     }  /* for (;;) */
103*01826a49SYabin Cui     assert(0);  /* Unreachable */
104*01826a49SYabin Cui }
105*01826a49SYabin Cui 
106*01826a49SYabin Cui /* ZSTD_createThreadPool() : public access point */
ZSTD_createThreadPool(size_t numThreads)107*01826a49SYabin Cui POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
108*01826a49SYabin Cui     return POOL_create (numThreads, 0);
109*01826a49SYabin Cui }
110*01826a49SYabin Cui 
POOL_create(size_t numThreads,size_t queueSize)111*01826a49SYabin Cui POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
112*01826a49SYabin Cui     return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
113*01826a49SYabin Cui }
114*01826a49SYabin Cui 
POOL_create_advanced(size_t numThreads,size_t queueSize,ZSTD_customMem customMem)115*01826a49SYabin Cui POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
116*01826a49SYabin Cui                                ZSTD_customMem customMem)
117*01826a49SYabin Cui {
118*01826a49SYabin Cui     POOL_ctx* ctx;
119*01826a49SYabin Cui     /* Check parameters */
120*01826a49SYabin Cui     if (!numThreads) { return NULL; }
121*01826a49SYabin Cui     /* Allocate the context and zero initialize */
122*01826a49SYabin Cui     ctx = (POOL_ctx*)ZSTD_customCalloc(sizeof(POOL_ctx), customMem);
123*01826a49SYabin Cui     if (!ctx) { return NULL; }
124*01826a49SYabin Cui     /* Initialize the job queue.
125*01826a49SYabin Cui      * It needs one extra space since one space is wasted to differentiate
126*01826a49SYabin Cui      * empty and full queues.
127*01826a49SYabin Cui      */
128*01826a49SYabin Cui     ctx->queueSize = queueSize + 1;
129*01826a49SYabin Cui     ctx->queue = (POOL_job*)ZSTD_customCalloc(ctx->queueSize * sizeof(POOL_job), customMem);
130*01826a49SYabin Cui     ctx->queueHead = 0;
131*01826a49SYabin Cui     ctx->queueTail = 0;
132*01826a49SYabin Cui     ctx->numThreadsBusy = 0;
133*01826a49SYabin Cui     ctx->queueEmpty = 1;
134*01826a49SYabin Cui     {
135*01826a49SYabin Cui         int error = 0;
136*01826a49SYabin Cui         error |= ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
137*01826a49SYabin Cui         error |= ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
138*01826a49SYabin Cui         error |= ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
139*01826a49SYabin Cui         if (error) { POOL_free(ctx); return NULL; }
140*01826a49SYabin Cui     }
141*01826a49SYabin Cui     ctx->shutdown = 0;
142*01826a49SYabin Cui     /* Allocate space for the thread handles */
143*01826a49SYabin Cui     ctx->threads = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
144*01826a49SYabin Cui     ctx->threadCapacity = 0;
145*01826a49SYabin Cui     ctx->customMem = customMem;
146*01826a49SYabin Cui     /* Check for errors */
147*01826a49SYabin Cui     if (!ctx->threads || !ctx->queue) { POOL_free(ctx); return NULL; }
148*01826a49SYabin Cui     /* Initialize the threads */
149*01826a49SYabin Cui     {   size_t i;
150*01826a49SYabin Cui         for (i = 0; i < numThreads; ++i) {
151*01826a49SYabin Cui             if (ZSTD_pthread_create(&ctx->threads[i], NULL, &POOL_thread, ctx)) {
152*01826a49SYabin Cui                 ctx->threadCapacity = i;
153*01826a49SYabin Cui                 POOL_free(ctx);
154*01826a49SYabin Cui                 return NULL;
155*01826a49SYabin Cui         }   }
156*01826a49SYabin Cui         ctx->threadCapacity = numThreads;
157*01826a49SYabin Cui         ctx->threadLimit = numThreads;
158*01826a49SYabin Cui     }
159*01826a49SYabin Cui     return ctx;
160*01826a49SYabin Cui }
161*01826a49SYabin Cui 
162*01826a49SYabin Cui /*! POOL_join() :
163*01826a49SYabin Cui     Shutdown the queue, wake any sleeping threads, and join all of the threads.
164*01826a49SYabin Cui */
POOL_join(POOL_ctx * ctx)165*01826a49SYabin Cui static void POOL_join(POOL_ctx* ctx) {
166*01826a49SYabin Cui     /* Shut down the queue */
167*01826a49SYabin Cui     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
168*01826a49SYabin Cui     ctx->shutdown = 1;
169*01826a49SYabin Cui     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
170*01826a49SYabin Cui     /* Wake up sleeping threads */
171*01826a49SYabin Cui     ZSTD_pthread_cond_broadcast(&ctx->queuePushCond);
172*01826a49SYabin Cui     ZSTD_pthread_cond_broadcast(&ctx->queuePopCond);
173*01826a49SYabin Cui     /* Join all of the threads */
174*01826a49SYabin Cui     {   size_t i;
175*01826a49SYabin Cui         for (i = 0; i < ctx->threadCapacity; ++i) {
176*01826a49SYabin Cui             ZSTD_pthread_join(ctx->threads[i]);  /* note : could fail */
177*01826a49SYabin Cui     }   }
178*01826a49SYabin Cui }
179*01826a49SYabin Cui 
POOL_free(POOL_ctx * ctx)180*01826a49SYabin Cui void POOL_free(POOL_ctx *ctx) {
181*01826a49SYabin Cui     if (!ctx) { return; }
182*01826a49SYabin Cui     POOL_join(ctx);
183*01826a49SYabin Cui     ZSTD_pthread_mutex_destroy(&ctx->queueMutex);
184*01826a49SYabin Cui     ZSTD_pthread_cond_destroy(&ctx->queuePushCond);
185*01826a49SYabin Cui     ZSTD_pthread_cond_destroy(&ctx->queuePopCond);
186*01826a49SYabin Cui     ZSTD_customFree(ctx->queue, ctx->customMem);
187*01826a49SYabin Cui     ZSTD_customFree(ctx->threads, ctx->customMem);
188*01826a49SYabin Cui     ZSTD_customFree(ctx, ctx->customMem);
189*01826a49SYabin Cui }
190*01826a49SYabin Cui 
191*01826a49SYabin Cui /*! POOL_joinJobs() :
192*01826a49SYabin Cui  *  Waits for all queued jobs to finish executing.
193*01826a49SYabin Cui  */
POOL_joinJobs(POOL_ctx * ctx)194*01826a49SYabin Cui void POOL_joinJobs(POOL_ctx* ctx) {
195*01826a49SYabin Cui     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
196*01826a49SYabin Cui     while(!ctx->queueEmpty || ctx->numThreadsBusy > 0) {
197*01826a49SYabin Cui         ZSTD_pthread_cond_wait(&ctx->queuePushCond, &ctx->queueMutex);
198*01826a49SYabin Cui     }
199*01826a49SYabin Cui     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
200*01826a49SYabin Cui }
201*01826a49SYabin Cui 
ZSTD_freeThreadPool(ZSTD_threadPool * pool)202*01826a49SYabin Cui void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
203*01826a49SYabin Cui   POOL_free (pool);
204*01826a49SYabin Cui }
205*01826a49SYabin Cui 
POOL_sizeof(const POOL_ctx * ctx)206*01826a49SYabin Cui size_t POOL_sizeof(const POOL_ctx* ctx) {
207*01826a49SYabin Cui     if (ctx==NULL) return 0;  /* supports sizeof NULL */
208*01826a49SYabin Cui     return sizeof(*ctx)
209*01826a49SYabin Cui         + ctx->queueSize * sizeof(POOL_job)
210*01826a49SYabin Cui         + ctx->threadCapacity * sizeof(ZSTD_pthread_t);
211*01826a49SYabin Cui }
212*01826a49SYabin Cui 
213*01826a49SYabin Cui 
214*01826a49SYabin Cui /* @return : 0 on success, 1 on error */
POOL_resize_internal(POOL_ctx * ctx,size_t numThreads)215*01826a49SYabin Cui static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
216*01826a49SYabin Cui {
217*01826a49SYabin Cui     if (numThreads <= ctx->threadCapacity) {
218*01826a49SYabin Cui         if (!numThreads) return 1;
219*01826a49SYabin Cui         ctx->threadLimit = numThreads;
220*01826a49SYabin Cui         return 0;
221*01826a49SYabin Cui     }
222*01826a49SYabin Cui     /* numThreads > threadCapacity */
223*01826a49SYabin Cui     {   ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
224*01826a49SYabin Cui         if (!threadPool) return 1;
225*01826a49SYabin Cui         /* replace existing thread pool */
226*01826a49SYabin Cui         ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(ZSTD_pthread_t));
227*01826a49SYabin Cui         ZSTD_customFree(ctx->threads, ctx->customMem);
228*01826a49SYabin Cui         ctx->threads = threadPool;
229*01826a49SYabin Cui         /* Initialize additional threads */
230*01826a49SYabin Cui         {   size_t threadId;
231*01826a49SYabin Cui             for (threadId = ctx->threadCapacity; threadId < numThreads; ++threadId) {
232*01826a49SYabin Cui                 if (ZSTD_pthread_create(&threadPool[threadId], NULL, &POOL_thread, ctx)) {
233*01826a49SYabin Cui                     ctx->threadCapacity = threadId;
234*01826a49SYabin Cui                     return 1;
235*01826a49SYabin Cui             }   }
236*01826a49SYabin Cui     }   }
237*01826a49SYabin Cui     /* successfully expanded */
238*01826a49SYabin Cui     ctx->threadCapacity = numThreads;
239*01826a49SYabin Cui     ctx->threadLimit = numThreads;
240*01826a49SYabin Cui     return 0;
241*01826a49SYabin Cui }
242*01826a49SYabin Cui 
243*01826a49SYabin Cui /* @return : 0 on success, 1 on error */
POOL_resize(POOL_ctx * ctx,size_t numThreads)244*01826a49SYabin Cui int POOL_resize(POOL_ctx* ctx, size_t numThreads)
245*01826a49SYabin Cui {
246*01826a49SYabin Cui     int result;
247*01826a49SYabin Cui     if (ctx==NULL) return 1;
248*01826a49SYabin Cui     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
249*01826a49SYabin Cui     result = POOL_resize_internal(ctx, numThreads);
250*01826a49SYabin Cui     ZSTD_pthread_cond_broadcast(&ctx->queuePopCond);
251*01826a49SYabin Cui     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
252*01826a49SYabin Cui     return result;
253*01826a49SYabin Cui }
254*01826a49SYabin Cui 
255*01826a49SYabin Cui /**
256*01826a49SYabin Cui  * Returns 1 if the queue is full and 0 otherwise.
257*01826a49SYabin Cui  *
258*01826a49SYabin Cui  * When queueSize is 1 (pool was created with an intended queueSize of 0),
259*01826a49SYabin Cui  * then a queue is empty if there is a thread free _and_ no job is waiting.
260*01826a49SYabin Cui  */
isQueueFull(POOL_ctx const * ctx)261*01826a49SYabin Cui static int isQueueFull(POOL_ctx const* ctx) {
262*01826a49SYabin Cui     if (ctx->queueSize > 1) {
263*01826a49SYabin Cui         return ctx->queueHead == ((ctx->queueTail + 1) % ctx->queueSize);
264*01826a49SYabin Cui     } else {
265*01826a49SYabin Cui         return (ctx->numThreadsBusy == ctx->threadLimit) ||
266*01826a49SYabin Cui                !ctx->queueEmpty;
267*01826a49SYabin Cui     }
268*01826a49SYabin Cui }
269*01826a49SYabin Cui 
270*01826a49SYabin Cui 
271*01826a49SYabin Cui static void
POOL_add_internal(POOL_ctx * ctx,POOL_function function,void * opaque)272*01826a49SYabin Cui POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
273*01826a49SYabin Cui {
274*01826a49SYabin Cui     POOL_job job;
275*01826a49SYabin Cui     job.function = function;
276*01826a49SYabin Cui     job.opaque = opaque;
277*01826a49SYabin Cui     assert(ctx != NULL);
278*01826a49SYabin Cui     if (ctx->shutdown) return;
279*01826a49SYabin Cui 
280*01826a49SYabin Cui     ctx->queueEmpty = 0;
281*01826a49SYabin Cui     ctx->queue[ctx->queueTail] = job;
282*01826a49SYabin Cui     ctx->queueTail = (ctx->queueTail + 1) % ctx->queueSize;
283*01826a49SYabin Cui     ZSTD_pthread_cond_signal(&ctx->queuePopCond);
284*01826a49SYabin Cui }
285*01826a49SYabin Cui 
POOL_add(POOL_ctx * ctx,POOL_function function,void * opaque)286*01826a49SYabin Cui void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque)
287*01826a49SYabin Cui {
288*01826a49SYabin Cui     assert(ctx != NULL);
289*01826a49SYabin Cui     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
290*01826a49SYabin Cui     /* Wait until there is space in the queue for the new job */
291*01826a49SYabin Cui     while (isQueueFull(ctx) && (!ctx->shutdown)) {
292*01826a49SYabin Cui         ZSTD_pthread_cond_wait(&ctx->queuePushCond, &ctx->queueMutex);
293*01826a49SYabin Cui     }
294*01826a49SYabin Cui     POOL_add_internal(ctx, function, opaque);
295*01826a49SYabin Cui     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
296*01826a49SYabin Cui }
297*01826a49SYabin Cui 
298*01826a49SYabin Cui 
POOL_tryAdd(POOL_ctx * ctx,POOL_function function,void * opaque)299*01826a49SYabin Cui int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque)
300*01826a49SYabin Cui {
301*01826a49SYabin Cui     assert(ctx != NULL);
302*01826a49SYabin Cui     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
303*01826a49SYabin Cui     if (isQueueFull(ctx)) {
304*01826a49SYabin Cui         ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
305*01826a49SYabin Cui         return 0;
306*01826a49SYabin Cui     }
307*01826a49SYabin Cui     POOL_add_internal(ctx, function, opaque);
308*01826a49SYabin Cui     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
309*01826a49SYabin Cui     return 1;
310*01826a49SYabin Cui }
311*01826a49SYabin Cui 
312*01826a49SYabin Cui 
313*01826a49SYabin Cui #else  /* ZSTD_MULTITHREAD  not defined */
314*01826a49SYabin Cui 
315*01826a49SYabin Cui /* ========================== */
316*01826a49SYabin Cui /* No multi-threading support */
317*01826a49SYabin Cui /* ========================== */
318*01826a49SYabin Cui 
319*01826a49SYabin Cui 
320*01826a49SYabin Cui /* We don't need any data, but if it is empty, malloc() might return NULL. */
321*01826a49SYabin Cui struct POOL_ctx_s {
322*01826a49SYabin Cui     int dummy;
323*01826a49SYabin Cui };
324*01826a49SYabin Cui static POOL_ctx g_poolCtx;
325*01826a49SYabin Cui 
POOL_create(size_t numThreads,size_t queueSize)326*01826a49SYabin Cui POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
327*01826a49SYabin Cui     return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
328*01826a49SYabin Cui }
329*01826a49SYabin Cui 
330*01826a49SYabin Cui POOL_ctx*
POOL_create_advanced(size_t numThreads,size_t queueSize,ZSTD_customMem customMem)331*01826a49SYabin Cui POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem)
332*01826a49SYabin Cui {
333*01826a49SYabin Cui     (void)numThreads;
334*01826a49SYabin Cui     (void)queueSize;
335*01826a49SYabin Cui     (void)customMem;
336*01826a49SYabin Cui     return &g_poolCtx;
337*01826a49SYabin Cui }
338*01826a49SYabin Cui 
POOL_free(POOL_ctx * ctx)339*01826a49SYabin Cui void POOL_free(POOL_ctx* ctx) {
340*01826a49SYabin Cui     assert(!ctx || ctx == &g_poolCtx);
341*01826a49SYabin Cui     (void)ctx;
342*01826a49SYabin Cui }
343*01826a49SYabin Cui 
POOL_joinJobs(POOL_ctx * ctx)344*01826a49SYabin Cui void POOL_joinJobs(POOL_ctx* ctx){
345*01826a49SYabin Cui     assert(!ctx || ctx == &g_poolCtx);
346*01826a49SYabin Cui     (void)ctx;
347*01826a49SYabin Cui }
348*01826a49SYabin Cui 
POOL_resize(POOL_ctx * ctx,size_t numThreads)349*01826a49SYabin Cui int POOL_resize(POOL_ctx* ctx, size_t numThreads) {
350*01826a49SYabin Cui     (void)ctx; (void)numThreads;
351*01826a49SYabin Cui     return 0;
352*01826a49SYabin Cui }
353*01826a49SYabin Cui 
POOL_add(POOL_ctx * ctx,POOL_function function,void * opaque)354*01826a49SYabin Cui void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque) {
355*01826a49SYabin Cui     (void)ctx;
356*01826a49SYabin Cui     function(opaque);
357*01826a49SYabin Cui }
358*01826a49SYabin Cui 
POOL_tryAdd(POOL_ctx * ctx,POOL_function function,void * opaque)359*01826a49SYabin Cui int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque) {
360*01826a49SYabin Cui     (void)ctx;
361*01826a49SYabin Cui     function(opaque);
362*01826a49SYabin Cui     return 1;
363*01826a49SYabin Cui }
364*01826a49SYabin Cui 
POOL_sizeof(const POOL_ctx * ctx)365*01826a49SYabin Cui size_t POOL_sizeof(const POOL_ctx* ctx) {
366*01826a49SYabin Cui     if (ctx==NULL) return 0;  /* supports sizeof NULL */
367*01826a49SYabin Cui     assert(ctx == &g_poolCtx);
368*01826a49SYabin Cui     return sizeof(*ctx);
369*01826a49SYabin Cui }
370*01826a49SYabin Cui 
371*01826a49SYabin Cui #endif  /* ZSTD_MULTITHREAD */
372