pool.h
74 lines
| 2.1 KiB
| text/x-c
|
CLexer
Gregory Szorc
|
r37513 | /* | ||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc. | ||||
Gregory Szorc
|
r30895 | * All rights reserved. | ||
* | ||||
Gregory Szorc
|
r37513 | * This source code is licensed under both the BSD-style license (found in the | ||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found | ||||
* in the COPYING file in the root directory of this source tree). | ||||
* You may select, at your option, one of the above-listed licenses. | ||||
Gregory Szorc
|
r30895 | */ | ||
Gregory Szorc
|
r37513 | |||
Gregory Szorc
|
r30895 | #ifndef POOL_H | ||
#define POOL_H | ||||
#if defined (__cplusplus) | ||||
extern "C" { | ||||
#endif | ||||
#include <stddef.h> /* size_t */ | ||||
Gregory Szorc
|
r37513 | #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */ | ||
#include "zstd.h" | ||||
Gregory Szorc
|
r30895 | |||
typedef struct POOL_ctx_s POOL_ctx; | ||||
/*! POOL_create() : | ||||
Gregory Szorc
|
r37513 | * Create a thread pool with at most `numThreads` threads. | ||
* `numThreads` must be at least 1. | ||||
* The maximum number of queued jobs before blocking is `queueSize`. | ||||
* @return : POOL_ctx pointer on success, else NULL. | ||||
Gregory Szorc
|
r30895 | */ | ||
Gregory Szorc
|
r37513 | POOL_ctx* POOL_create(size_t numThreads, size_t queueSize); | ||
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem); | ||||
Gregory Szorc
|
r30895 | |||
/*! POOL_free() : | ||||
Free a thread pool returned by POOL_create(). | ||||
*/ | ||||
Gregory Szorc
|
r37513 | void POOL_free(POOL_ctx* ctx); | ||
/*! POOL_sizeof() : | ||||
return memory usage of pool returned by POOL_create(). | ||||
*/ | ||||
size_t POOL_sizeof(POOL_ctx* ctx); | ||||
Gregory Szorc
|
r30895 | |||
/*! POOL_function : | ||||
The function type that can be added to a thread pool. | ||||
*/ | ||||
Gregory Szorc
|
r37513 | typedef void (*POOL_function)(void*); | ||
Gregory Szorc
|
r30895 | /*! POOL_add_function : | ||
The function type for a generic thread pool add function. | ||||
*/ | ||||
Gregory Szorc
|
r37513 | typedef void (*POOL_add_function)(void*, POOL_function, void*); | ||
Gregory Szorc
|
r30895 | |||
/*! POOL_add() : | ||||
Gregory Szorc
|
r37513 | Add the job `function(opaque)` to the thread pool. `ctx` must be valid. | ||
Gregory Szorc
|
r30895 | 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. | ||||
*/ | ||||
Gregory Szorc
|
r37513 | void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque); | ||
/*! POOL_tryAdd() : | ||||
Add the job `function(opaque)` to the thread pool if a worker is available. | ||||
return immediately otherwise. | ||||
@return : 1 if successful, 0 if not. | ||||
*/ | ||||
int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque); | ||||
Gregory Szorc
|
r30895 | |||
#if defined (__cplusplus) | ||||
} | ||||
#endif | ||||
#endif | ||||