2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
14 #if defined (__cplusplus)
19 #include <stddef.h> /* size_t */
20 #include "zstd_internal.h" /* ZSTD_customMem */
22 typedef struct POOL_ctx_s POOL_ctx;
25 * Create a thread pool with at most `numThreads` threads.
26 * `numThreads` must be at least 1.
27 * The maximum number of queued jobs before blocking is `queueSize`.
28 * @return : POOL_ctx pointer on success, else NULL.
30 POOL_ctx *POOL_create(size_t numThreads, size_t queueSize);
32 POOL_ctx *POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem);
35 Free a thread pool returned by POOL_create().
37 void POOL_free(POOL_ctx *ctx);
40 return memory usage of pool returned by POOL_create().
42 size_t POOL_sizeof(POOL_ctx *ctx);
45 The function type that can be added to a thread pool.
47 typedef void (*POOL_function)(void *);
48 /*! POOL_add_function :
49 The function type for a generic thread pool add function.
51 typedef void (*POOL_add_function)(void *, POOL_function, void *);
54 Add the job `function(opaque)` to the thread pool.
55 Possibly blocks until there is room in the queue.
56 Note : The function may be executed asynchronously, so `opaque` must live until the function has been completed.
58 void POOL_add(void *ctx, POOL_function function, void *opaque);
61 #if defined (__cplusplus)