mirror of
https://github.com/facebook/zstd.git
synced 2025-12-01 00:02:43 -05:00
POOL_sizeof() only needs a const read-only reference
This commit is contained in:
parent
fb14e2288e
commit
b1978d60ee
@ -86,7 +86,7 @@ static void* POOL_thread(void* opaque) {
|
|||||||
{ POOL_job const job = ctx->queue[ctx->queueHead];
|
{ POOL_job const job = ctx->queue[ctx->queueHead];
|
||||||
ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
|
ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
|
||||||
ctx->numThreadsBusy++;
|
ctx->numThreadsBusy++;
|
||||||
ctx->queueEmpty = ctx->queueHead == ctx->queueTail;
|
ctx->queueEmpty = (ctx->queueHead == ctx->queueTail);
|
||||||
/* Unlock the mutex, signal a pusher, and run the job */
|
/* Unlock the mutex, signal a pusher, and run the job */
|
||||||
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
||||||
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
||||||
@ -105,6 +105,7 @@ static void* POOL_thread(void* opaque) {
|
|||||||
assert(0); /* Unreachable */
|
assert(0); /* Unreachable */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ZSTD_createThreadPool() : public access point */
|
||||||
POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
|
POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
|
||||||
return POOL_create (numThreads, 0);
|
return POOL_create (numThreads, 0);
|
||||||
}
|
}
|
||||||
@ -114,7 +115,8 @@ POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
||||||
ZSTD_customMem customMem) {
|
ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
POOL_ctx* ctx;
|
POOL_ctx* ctx;
|
||||||
/* Check parameters */
|
/* Check parameters */
|
||||||
if (!numThreads) { return NULL; }
|
if (!numThreads) { return NULL; }
|
||||||
@ -192,7 +194,7 @@ void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
|
|||||||
POOL_free (pool);
|
POOL_free (pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t POOL_sizeof(POOL_ctx *ctx) {
|
size_t POOL_sizeof(const POOL_ctx *ctx) {
|
||||||
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
||||||
return sizeof(*ctx)
|
return sizeof(*ctx)
|
||||||
+ ctx->queueSize * sizeof(POOL_job)
|
+ ctx->queueSize * sizeof(POOL_job)
|
||||||
@ -257,7 +259,8 @@ static int isQueueFull(POOL_ctx const* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
|
static void
|
||||||
|
POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
|
||||||
{
|
{
|
||||||
POOL_job const job = {function, opaque};
|
POOL_job const job = {function, opaque};
|
||||||
assert(ctx != NULL);
|
assert(ctx != NULL);
|
||||||
@ -313,7 +316,9 @@ POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
|||||||
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
(void)numThreads;
|
(void)numThreads;
|
||||||
(void)queueSize;
|
(void)queueSize;
|
||||||
(void)customMem;
|
(void)customMem;
|
||||||
|
|||||||
@ -53,7 +53,7 @@ int POOL_resize(POOL_ctx* ctx, size_t numThreads);
|
|||||||
* @return threadpool memory usage
|
* @return threadpool memory usage
|
||||||
* note : compatible with NULL (returns 0 in this case)
|
* note : compatible with NULL (returns 0 in this case)
|
||||||
*/
|
*/
|
||||||
size_t POOL_sizeof(POOL_ctx* ctx);
|
size_t POOL_sizeof(const POOL_ctx* ctx);
|
||||||
|
|
||||||
/*! POOL_function :
|
/*! POOL_function :
|
||||||
* The function type that can be added to a thread pool.
|
* The function type that can be added to a thread pool.
|
||||||
@ -70,7 +70,7 @@ void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
|
|||||||
|
|
||||||
|
|
||||||
/*! POOL_tryAdd() :
|
/*! POOL_tryAdd() :
|
||||||
* Add the job `function(opaque)` to thread pool _if_ a worker is available.
|
* Add the job `function(opaque)` to thread pool _if_ a queue slot is available.
|
||||||
* Returns immediately even if not (does not block).
|
* Returns immediately even if not (does not block).
|
||||||
* @return : 1 if successful, 0 if not.
|
* @return : 1 if successful, 0 if not.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user