diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-09-03 14:45:28 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-09-03 14:46:23 +0100 |
commit | dc542fee771da80377bcac16136c0972a8faadb4 (patch) | |
tree | db7a15a9a90d1bcd2fa948641b45aa4900067598 /contrib/zstd/pool.h | |
parent | 74a6f8cc42d902ef10fe70b633a4d11735e578d2 (diff) | |
download | rspamd-dc542fee771da80377bcac16136c0972a8faadb4.tar.gz rspamd-dc542fee771da80377bcac16136c0972a8faadb4.zip |
[Rework] Update zstd to 1.4.5
Diffstat (limited to 'contrib/zstd/pool.h')
-rw-r--r-- | contrib/zstd/pool.h | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/contrib/zstd/pool.h b/contrib/zstd/pool.h index 08c63715a..259bafc97 100644 --- a/contrib/zstd/pool.h +++ b/contrib/zstd/pool.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. + * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc. * All rights reserved. * * This source code is licensed under both the BSD-style license (found in the @@ -17,7 +17,8 @@ extern "C" { #include <stddef.h> /* size_t */ -#include "zstd_internal.h" /* ZSTD_customMem */ +#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */ +#include "../zstd.h" typedef struct POOL_ctx_s POOL_ctx; @@ -27,35 +28,53 @@ typedef struct POOL_ctx_s POOL_ctx; * The maximum number of queued jobs before blocking is `queueSize`. * @return : POOL_ctx pointer on success, else NULL. */ -POOL_ctx *POOL_create(size_t numThreads, size_t queueSize); +POOL_ctx* POOL_create(size_t numThreads, size_t queueSize); -POOL_ctx *POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem); +POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, + ZSTD_customMem customMem); /*! POOL_free() : - Free a thread pool returned by POOL_create(). -*/ -void POOL_free(POOL_ctx *ctx); + * Free a thread pool returned by POOL_create(). + */ +void POOL_free(POOL_ctx* ctx); + +/*! POOL_resize() : + * Expands or shrinks pool's number of threads. + * This is more efficient than releasing + creating a new context, + * since it tries to preserve and re-use existing threads. + * `numThreads` must be at least 1. + * @return : 0 when resize was successful, + * !0 (typically 1) if there is an error. + * note : only numThreads can be resized, queueSize remains unchanged. + */ +int POOL_resize(POOL_ctx* ctx, size_t numThreads); /*! POOL_sizeof() : - return memory usage of pool returned by POOL_create(). -*/ -size_t POOL_sizeof(POOL_ctx *ctx); + * @return threadpool memory usage + * note : compatible with NULL (returns 0 in this case) + */ +size_t POOL_sizeof(POOL_ctx* ctx); /*! POOL_function : - The function type that can be added to a thread pool. -*/ -typedef void (*POOL_function)(void *); -/*! POOL_add_function : - The function type for a generic thread pool add function. -*/ -typedef void (*POOL_add_function)(void *, POOL_function, void *); + * The function type that can be added to a thread pool. + */ +typedef void (*POOL_function)(void*); /*! POOL_add() : - Add the job `function(opaque)` to the thread pool. - Possibly blocks until there is room in the queue. - Note : The function may be executed asynchronously, so `opaque` must live until the function has been completed. -*/ -void POOL_add(void *ctx, POOL_function function, void *opaque); + * Add the job `function(opaque)` to the thread pool. `ctx` must be valid. + * Possibly blocks until there is room in the queue. + * Note : The function may be executed asynchronously, + * therefore, `opaque` must live until function has been completed. + */ +void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque); + + +/*! POOL_tryAdd() : + * Add the job `function(opaque)` to thread pool _if_ a worker is available. + * Returns immediately even if not (does not block). + * @return : 1 if successful, 0 if not. + */ +int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque); #if defined (__cplusplus) |