xref: /freebsd/sys/contrib/zstd/lib/common/pool.c (revision 5ff13fbc199bdf5f0572845351c68ee5ca828e71)
10c16b537SWarner Losh /*
2*5ff13fbcSAllan Jude  * Copyright (c) Yann Collet, Facebook, Inc.
30c16b537SWarner Losh  * All rights reserved.
40c16b537SWarner Losh  *
50c16b537SWarner Losh  * This source code is licensed under both the BSD-style license (found in the
60c16b537SWarner Losh  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
70c16b537SWarner Losh  * in the COPYING file in the root directory of this source tree).
80c16b537SWarner Losh  * You may select, at your option, one of the above-listed licenses.
90c16b537SWarner Losh  */
100c16b537SWarner Losh 
110c16b537SWarner Losh 
120c16b537SWarner Losh /* ======   Dependencies   ======= */
13f7cd7fe5SConrad Meyer #include "zstd_deps.h" /* size_t */
140f743729SConrad Meyer #include "debug.h"     /* assert */
15f7cd7fe5SConrad Meyer #include "zstd_internal.h"  /* ZSTD_customMalloc, ZSTD_customFree */
160f743729SConrad Meyer #include "pool.h"
170c16b537SWarner Losh 
180c16b537SWarner Losh /* ======   Compiler specifics   ====== */
190c16b537SWarner Losh #if defined(_MSC_VER)
200c16b537SWarner Losh #  pragma warning(disable : 4204)        /* disable: C4204: non-constant aggregate initializer */
210c16b537SWarner Losh #endif
220c16b537SWarner Losh 
230c16b537SWarner Losh 
240c16b537SWarner Losh #ifdef ZSTD_MULTITHREAD
250c16b537SWarner Losh 
260c16b537SWarner Losh #include "threading.h"   /* pthread adaptation */
270c16b537SWarner Losh 
280c16b537SWarner Losh /* A job is a function and an opaque argument */
290c16b537SWarner Losh typedef struct POOL_job_s {
300c16b537SWarner Losh     POOL_function function;
310c16b537SWarner Losh     void *opaque;
320c16b537SWarner Losh } POOL_job;
330c16b537SWarner Losh 
340c16b537SWarner Losh struct POOL_ctx_s {
350c16b537SWarner Losh     ZSTD_customMem customMem;
360c16b537SWarner Losh     /* Keep track of the threads */
370c16b537SWarner Losh     ZSTD_pthread_t* threads;
380f743729SConrad Meyer     size_t threadCapacity;
390f743729SConrad Meyer     size_t threadLimit;
400c16b537SWarner Losh 
410c16b537SWarner Losh     /* The queue is a circular buffer */
420c16b537SWarner Losh     POOL_job *queue;
430c16b537SWarner Losh     size_t queueHead;
440c16b537SWarner Losh     size_t queueTail;
450c16b537SWarner Losh     size_t queueSize;
460c16b537SWarner Losh 
470c16b537SWarner Losh     /* The number of threads working on jobs */
480c16b537SWarner Losh     size_t numThreadsBusy;
490c16b537SWarner Losh     /* Indicates if the queue is empty */
500c16b537SWarner Losh     int queueEmpty;
510c16b537SWarner Losh 
520c16b537SWarner Losh     /* The mutex protects the queue */
530c16b537SWarner Losh     ZSTD_pthread_mutex_t queueMutex;
540c16b537SWarner Losh     /* Condition variable for pushers to wait on when the queue is full */
550c16b537SWarner Losh     ZSTD_pthread_cond_t queuePushCond;
560c16b537SWarner Losh     /* Condition variables for poppers to wait on when the queue is empty */
570c16b537SWarner Losh     ZSTD_pthread_cond_t queuePopCond;
580c16b537SWarner Losh     /* Indicates if the queue is shutting down */
590c16b537SWarner Losh     int shutdown;
600c16b537SWarner Losh };
610c16b537SWarner Losh 
620c16b537SWarner Losh /* POOL_thread() :
630f743729SConrad Meyer  * Work thread for the thread pool.
640f743729SConrad Meyer  * Waits for jobs and executes them.
650f743729SConrad Meyer  * @returns : NULL on failure else non-null.
660c16b537SWarner Losh  */
POOL_thread(void * opaque)670c16b537SWarner Losh static void* POOL_thread(void* opaque) {
680c16b537SWarner Losh     POOL_ctx* const ctx = (POOL_ctx*)opaque;
690c16b537SWarner Losh     if (!ctx) { return NULL; }
700c16b537SWarner Losh     for (;;) {
710c16b537SWarner Losh         /* Lock the mutex and wait for a non-empty queue or until shutdown */
720c16b537SWarner Losh         ZSTD_pthread_mutex_lock(&ctx->queueMutex);
730c16b537SWarner Losh 
740f743729SConrad Meyer         while ( ctx->queueEmpty
750f743729SConrad Meyer             || (ctx->numThreadsBusy >= ctx->threadLimit) ) {
760f743729SConrad Meyer             if (ctx->shutdown) {
770f743729SConrad Meyer                 /* even if !queueEmpty, (possible if numThreadsBusy >= threadLimit),
780f743729SConrad Meyer                  * a few threads will be shutdown while !queueEmpty,
790f743729SConrad Meyer                  * but enough threads will remain active to finish the queue */
800c16b537SWarner Losh                 ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
810c16b537SWarner Losh                 return opaque;
820c16b537SWarner Losh             }
830f743729SConrad Meyer             ZSTD_pthread_cond_wait(&ctx->queuePopCond, &ctx->queueMutex);
840f743729SConrad Meyer         }
850c16b537SWarner Losh         /* Pop a job off the queue */
860c16b537SWarner Losh         {   POOL_job const job = ctx->queue[ctx->queueHead];
870c16b537SWarner Losh             ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
880c16b537SWarner Losh             ctx->numThreadsBusy++;
89*5ff13fbcSAllan Jude             ctx->queueEmpty = (ctx->queueHead == ctx->queueTail);
900c16b537SWarner Losh             /* Unlock the mutex, signal a pusher, and run the job */
910c16b537SWarner Losh             ZSTD_pthread_cond_signal(&ctx->queuePushCond);
92a0483764SConrad Meyer             ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
930c16b537SWarner Losh 
940c16b537SWarner Losh             job.function(job.opaque);
950c16b537SWarner Losh 
960c16b537SWarner Losh             /* If the intended queue size was 0, signal after finishing job */
970c16b537SWarner Losh             ZSTD_pthread_mutex_lock(&ctx->queueMutex);
980c16b537SWarner Losh             ctx->numThreadsBusy--;
990f743729SConrad Meyer             if (ctx->queueSize == 1) {
1000c16b537SWarner Losh                 ZSTD_pthread_cond_signal(&ctx->queuePushCond);
1010f743729SConrad Meyer             }
1020f743729SConrad Meyer             ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
1030f743729SConrad Meyer         }
1040c16b537SWarner Losh     }  /* for (;;) */
1050f743729SConrad Meyer     assert(0);  /* Unreachable */
1060c16b537SWarner Losh }
1070c16b537SWarner Losh 
108*5ff13fbcSAllan Jude /* ZSTD_createThreadPool() : public access point */
ZSTD_createThreadPool(size_t numThreads)109f7cd7fe5SConrad Meyer POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
110f7cd7fe5SConrad Meyer     return POOL_create (numThreads, 0);
111f7cd7fe5SConrad Meyer }
112f7cd7fe5SConrad Meyer 
POOL_create(size_t numThreads,size_t queueSize)1130c16b537SWarner Losh POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
1140c16b537SWarner Losh     return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
1150c16b537SWarner Losh }
1160c16b537SWarner Losh 
POOL_create_advanced(size_t numThreads,size_t queueSize,ZSTD_customMem customMem)1170f743729SConrad Meyer POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
118*5ff13fbcSAllan Jude                                ZSTD_customMem customMem)
119*5ff13fbcSAllan Jude {
1200c16b537SWarner Losh     POOL_ctx* ctx;
1210f743729SConrad Meyer     /* Check parameters */
1220c16b537SWarner Losh     if (!numThreads) { return NULL; }
1230c16b537SWarner Losh     /* Allocate the context and zero initialize */
124f7cd7fe5SConrad Meyer     ctx = (POOL_ctx*)ZSTD_customCalloc(sizeof(POOL_ctx), customMem);
1250c16b537SWarner Losh     if (!ctx) { return NULL; }
1260c16b537SWarner Losh     /* Initialize the job queue.
1270f743729SConrad Meyer      * It needs one extra space since one space is wasted to differentiate
1280f743729SConrad Meyer      * empty and full queues.
1290c16b537SWarner Losh      */
1300c16b537SWarner Losh     ctx->queueSize = queueSize + 1;
131f7cd7fe5SConrad Meyer     ctx->queue = (POOL_job*)ZSTD_customMalloc(ctx->queueSize * sizeof(POOL_job), customMem);
1320c16b537SWarner Losh     ctx->queueHead = 0;
1330c16b537SWarner Losh     ctx->queueTail = 0;
1340c16b537SWarner Losh     ctx->numThreadsBusy = 0;
1350c16b537SWarner Losh     ctx->queueEmpty = 1;
1369cbefe25SConrad Meyer     {
1379cbefe25SConrad Meyer         int error = 0;
1389cbefe25SConrad Meyer         error |= ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
1399cbefe25SConrad Meyer         error |= ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
1409cbefe25SConrad Meyer         error |= ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
1419cbefe25SConrad Meyer         if (error) { POOL_free(ctx); return NULL; }
1429cbefe25SConrad Meyer     }
1430c16b537SWarner Losh     ctx->shutdown = 0;
1440c16b537SWarner Losh     /* Allocate space for the thread handles */
145f7cd7fe5SConrad Meyer     ctx->threads = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
1460f743729SConrad Meyer     ctx->threadCapacity = 0;
1470c16b537SWarner Losh     ctx->customMem = customMem;
1480c16b537SWarner Losh     /* Check for errors */
1490c16b537SWarner Losh     if (!ctx->threads || !ctx->queue) { POOL_free(ctx); return NULL; }
1500c16b537SWarner Losh     /* Initialize the threads */
1510c16b537SWarner Losh     {   size_t i;
1520c16b537SWarner Losh         for (i = 0; i < numThreads; ++i) {
1530c16b537SWarner Losh             if (ZSTD_pthread_create(&ctx->threads[i], NULL, &POOL_thread, ctx)) {
1540f743729SConrad Meyer                 ctx->threadCapacity = i;
1550c16b537SWarner Losh                 POOL_free(ctx);
1560c16b537SWarner Losh                 return NULL;
1570c16b537SWarner Losh         }   }
1580f743729SConrad Meyer         ctx->threadCapacity = numThreads;
1590f743729SConrad Meyer         ctx->threadLimit = numThreads;
1600c16b537SWarner Losh     }
1610c16b537SWarner Losh     return ctx;
1620c16b537SWarner Losh }
1630c16b537SWarner Losh 
1640c16b537SWarner Losh /*! POOL_join() :
1650c16b537SWarner Losh     Shutdown the queue, wake any sleeping threads, and join all of the threads.
1660c16b537SWarner Losh */
POOL_join(POOL_ctx * ctx)1670c16b537SWarner Losh static void POOL_join(POOL_ctx* ctx) {
1680c16b537SWarner Losh     /* Shut down the queue */
1690c16b537SWarner Losh     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
1700c16b537SWarner Losh     ctx->shutdown = 1;
1710c16b537SWarner Losh     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
1720c16b537SWarner Losh     /* Wake up sleeping threads */
1730c16b537SWarner Losh     ZSTD_pthread_cond_broadcast(&ctx->queuePushCond);
1740c16b537SWarner Losh     ZSTD_pthread_cond_broadcast(&ctx->queuePopCond);
1750c16b537SWarner Losh     /* Join all of the threads */
1760c16b537SWarner Losh     {   size_t i;
1770f743729SConrad Meyer         for (i = 0; i < ctx->threadCapacity; ++i) {
1780f743729SConrad Meyer             ZSTD_pthread_join(ctx->threads[i], NULL);  /* note : could fail */
1790c16b537SWarner Losh     }   }
1800c16b537SWarner Losh }
1810c16b537SWarner Losh 
POOL_free(POOL_ctx * ctx)1820c16b537SWarner Losh void POOL_free(POOL_ctx *ctx) {
1830c16b537SWarner Losh     if (!ctx) { return; }
1840c16b537SWarner Losh     POOL_join(ctx);
1850c16b537SWarner Losh     ZSTD_pthread_mutex_destroy(&ctx->queueMutex);
1860c16b537SWarner Losh     ZSTD_pthread_cond_destroy(&ctx->queuePushCond);
1870c16b537SWarner Losh     ZSTD_pthread_cond_destroy(&ctx->queuePopCond);
188f7cd7fe5SConrad Meyer     ZSTD_customFree(ctx->queue, ctx->customMem);
189f7cd7fe5SConrad Meyer     ZSTD_customFree(ctx->threads, ctx->customMem);
190f7cd7fe5SConrad Meyer     ZSTD_customFree(ctx, ctx->customMem);
1910c16b537SWarner Losh }
1920c16b537SWarner Losh 
ZSTD_freeThreadPool(ZSTD_threadPool * pool)193f7cd7fe5SConrad Meyer void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
194f7cd7fe5SConrad Meyer   POOL_free (pool);
195f7cd7fe5SConrad Meyer }
1960f743729SConrad Meyer 
POOL_sizeof(const POOL_ctx * ctx)197*5ff13fbcSAllan Jude size_t POOL_sizeof(const POOL_ctx* ctx) {
1980c16b537SWarner Losh     if (ctx==NULL) return 0;  /* supports sizeof NULL */
1990c16b537SWarner Losh     return sizeof(*ctx)
2000c16b537SWarner Losh         + ctx->queueSize * sizeof(POOL_job)
2010f743729SConrad Meyer         + ctx->threadCapacity * sizeof(ZSTD_pthread_t);
2020f743729SConrad Meyer }
2030f743729SConrad Meyer 
2040f743729SConrad Meyer 
2050f743729SConrad Meyer /* @return : 0 on success, 1 on error */
POOL_resize_internal(POOL_ctx * ctx,size_t numThreads)2060f743729SConrad Meyer static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
2070f743729SConrad Meyer {
2080f743729SConrad Meyer     if (numThreads <= ctx->threadCapacity) {
2090f743729SConrad Meyer         if (!numThreads) return 1;
2100f743729SConrad Meyer         ctx->threadLimit = numThreads;
2110f743729SConrad Meyer         return 0;
2120f743729SConrad Meyer     }
2130f743729SConrad Meyer     /* numThreads > threadCapacity */
214f7cd7fe5SConrad Meyer     {   ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
2150f743729SConrad Meyer         if (!threadPool) return 1;
2160f743729SConrad Meyer         /* replace existing thread pool */
217f7cd7fe5SConrad Meyer         ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
218f7cd7fe5SConrad Meyer         ZSTD_customFree(ctx->threads, ctx->customMem);
2190f743729SConrad Meyer         ctx->threads = threadPool;
2200f743729SConrad Meyer         /* Initialize additional threads */
2210f743729SConrad Meyer         {   size_t threadId;
2220f743729SConrad Meyer             for (threadId = ctx->threadCapacity; threadId < numThreads; ++threadId) {
2230f743729SConrad Meyer                 if (ZSTD_pthread_create(&threadPool[threadId], NULL, &POOL_thread, ctx)) {
2240f743729SConrad Meyer                     ctx->threadCapacity = threadId;
2250f743729SConrad Meyer                     return 1;
2260f743729SConrad Meyer             }   }
2270f743729SConrad Meyer     }   }
2280f743729SConrad Meyer     /* successfully expanded */
2290f743729SConrad Meyer     ctx->threadCapacity = numThreads;
2300f743729SConrad Meyer     ctx->threadLimit = numThreads;
2310f743729SConrad Meyer     return 0;
2320f743729SConrad Meyer }
2330f743729SConrad Meyer 
2340f743729SConrad Meyer /* @return : 0 on success, 1 on error */
POOL_resize(POOL_ctx * ctx,size_t numThreads)2350f743729SConrad Meyer int POOL_resize(POOL_ctx* ctx, size_t numThreads)
2360f743729SConrad Meyer {
2370f743729SConrad Meyer     int result;
2380f743729SConrad Meyer     if (ctx==NULL) return 1;
2390f743729SConrad Meyer     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
2400f743729SConrad Meyer     result = POOL_resize_internal(ctx, numThreads);
2410f743729SConrad Meyer     ZSTD_pthread_cond_broadcast(&ctx->queuePopCond);
2420f743729SConrad Meyer     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
2430f743729SConrad Meyer     return result;
2440c16b537SWarner Losh }
2450c16b537SWarner Losh 
2460c16b537SWarner Losh /**
2470c16b537SWarner Losh  * Returns 1 if the queue is full and 0 otherwise.
2480c16b537SWarner Losh  *
2490f743729SConrad Meyer  * When queueSize is 1 (pool was created with an intended queueSize of 0),
2500f743729SConrad Meyer  * then a queue is empty if there is a thread free _and_ no job is waiting.
2510c16b537SWarner Losh  */
isQueueFull(POOL_ctx const * ctx)2520c16b537SWarner Losh static int isQueueFull(POOL_ctx const* ctx) {
2530c16b537SWarner Losh     if (ctx->queueSize > 1) {
2540c16b537SWarner Losh         return ctx->queueHead == ((ctx->queueTail + 1) % ctx->queueSize);
2550c16b537SWarner Losh     } else {
2560f743729SConrad Meyer         return (ctx->numThreadsBusy == ctx->threadLimit) ||
2570c16b537SWarner Losh                !ctx->queueEmpty;
2580c16b537SWarner Losh     }
2590c16b537SWarner Losh }
2600c16b537SWarner Losh 
2610c16b537SWarner Losh 
262*5ff13fbcSAllan Jude static void
POOL_add_internal(POOL_ctx * ctx,POOL_function function,void * opaque)263*5ff13fbcSAllan Jude POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
26419fcbaf1SConrad Meyer {
26519fcbaf1SConrad Meyer     POOL_job const job = {function, opaque};
26619fcbaf1SConrad Meyer     assert(ctx != NULL);
26719fcbaf1SConrad Meyer     if (ctx->shutdown) return;
2680c16b537SWarner Losh 
2690c16b537SWarner Losh     ctx->queueEmpty = 0;
2700c16b537SWarner Losh     ctx->queue[ctx->queueTail] = job;
2710c16b537SWarner Losh     ctx->queueTail = (ctx->queueTail + 1) % ctx->queueSize;
2720c16b537SWarner Losh     ZSTD_pthread_cond_signal(&ctx->queuePopCond);
2730c16b537SWarner Losh }
2740c16b537SWarner Losh 
POOL_add(POOL_ctx * ctx,POOL_function function,void * opaque)27519fcbaf1SConrad Meyer void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque)
27619fcbaf1SConrad Meyer {
27719fcbaf1SConrad Meyer     assert(ctx != NULL);
27819fcbaf1SConrad Meyer     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
27919fcbaf1SConrad Meyer     /* Wait until there is space in the queue for the new job */
28019fcbaf1SConrad Meyer     while (isQueueFull(ctx) && (!ctx->shutdown)) {
28119fcbaf1SConrad Meyer         ZSTD_pthread_cond_wait(&ctx->queuePushCond, &ctx->queueMutex);
28219fcbaf1SConrad Meyer     }
28319fcbaf1SConrad Meyer     POOL_add_internal(ctx, function, opaque);
28419fcbaf1SConrad Meyer     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
28519fcbaf1SConrad Meyer }
2860c16b537SWarner Losh 
28719fcbaf1SConrad Meyer 
POOL_tryAdd(POOL_ctx * ctx,POOL_function function,void * opaque)28819fcbaf1SConrad Meyer int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque)
28919fcbaf1SConrad Meyer {
29019fcbaf1SConrad Meyer     assert(ctx != NULL);
29119fcbaf1SConrad Meyer     ZSTD_pthread_mutex_lock(&ctx->queueMutex);
29219fcbaf1SConrad Meyer     if (isQueueFull(ctx)) {
29319fcbaf1SConrad Meyer         ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
29419fcbaf1SConrad Meyer         return 0;
29519fcbaf1SConrad Meyer     }
29619fcbaf1SConrad Meyer     POOL_add_internal(ctx, function, opaque);
29719fcbaf1SConrad Meyer     ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
29819fcbaf1SConrad Meyer     return 1;
29919fcbaf1SConrad Meyer }
30019fcbaf1SConrad Meyer 
30119fcbaf1SConrad Meyer 
30219fcbaf1SConrad Meyer #else  /* ZSTD_MULTITHREAD  not defined */
30319fcbaf1SConrad Meyer 
30419fcbaf1SConrad Meyer /* ========================== */
30519fcbaf1SConrad Meyer /* No multi-threading support */
30619fcbaf1SConrad Meyer /* ========================== */
30719fcbaf1SConrad Meyer 
30819fcbaf1SConrad Meyer 
30919fcbaf1SConrad Meyer /* We don't need any data, but if it is empty, malloc() might return NULL. */
3100c16b537SWarner Losh struct POOL_ctx_s {
3110c16b537SWarner Losh     int dummy;
3120c16b537SWarner Losh };
313f7cd7fe5SConrad Meyer static POOL_ctx g_poolCtx;
3140c16b537SWarner Losh 
POOL_create(size_t numThreads,size_t queueSize)3150c16b537SWarner Losh POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
3160c16b537SWarner Losh     return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
3170c16b537SWarner Losh }
3180c16b537SWarner Losh 
319*5ff13fbcSAllan Jude POOL_ctx*
POOL_create_advanced(size_t numThreads,size_t queueSize,ZSTD_customMem customMem)320*5ff13fbcSAllan Jude POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem)
321*5ff13fbcSAllan Jude {
3220c16b537SWarner Losh     (void)numThreads;
3230c16b537SWarner Losh     (void)queueSize;
3240c16b537SWarner Losh     (void)customMem;
325f7cd7fe5SConrad Meyer     return &g_poolCtx;
3260c16b537SWarner Losh }
3270c16b537SWarner Losh 
POOL_free(POOL_ctx * ctx)3280c16b537SWarner Losh void POOL_free(POOL_ctx* ctx) {
329f7cd7fe5SConrad Meyer     assert(!ctx || ctx == &g_poolCtx);
3300c16b537SWarner Losh     (void)ctx;
3310c16b537SWarner Losh }
3320c16b537SWarner Losh 
POOL_resize(POOL_ctx * ctx,size_t numThreads)3330f743729SConrad Meyer int POOL_resize(POOL_ctx* ctx, size_t numThreads) {
3340f743729SConrad Meyer     (void)ctx; (void)numThreads;
3350f743729SConrad Meyer     return 0;
3360f743729SConrad Meyer }
3370f743729SConrad Meyer 
POOL_add(POOL_ctx * ctx,POOL_function function,void * opaque)33819fcbaf1SConrad Meyer void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque) {
3390c16b537SWarner Losh     (void)ctx;
3400c16b537SWarner Losh     function(opaque);
3410c16b537SWarner Losh }
3420c16b537SWarner Losh 
POOL_tryAdd(POOL_ctx * ctx,POOL_function function,void * opaque)34319fcbaf1SConrad Meyer int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque) {
34419fcbaf1SConrad Meyer     (void)ctx;
34519fcbaf1SConrad Meyer     function(opaque);
34619fcbaf1SConrad Meyer     return 1;
34719fcbaf1SConrad Meyer }
34819fcbaf1SConrad Meyer 
POOL_sizeof(const POOL_ctx * ctx)349*5ff13fbcSAllan Jude size_t POOL_sizeof(const POOL_ctx* ctx) {
3500c16b537SWarner Losh     if (ctx==NULL) return 0;  /* supports sizeof NULL */
351f7cd7fe5SConrad Meyer     assert(ctx == &g_poolCtx);
3520c16b537SWarner Losh     return sizeof(*ctx);
3530c16b537SWarner Losh }
3540c16b537SWarner Losh 
3550c16b537SWarner Losh #endif  /* ZSTD_MULTITHREAD */
356