2017-08-18 16:52:05 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
2016-12-29 23:39:44 -08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-18 16:52:05 -07:00
|
|
|
* 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).
|
2017-09-08 00:09:23 -07:00
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
2016-12-29 23:39:44 -08:00
|
|
|
*/
|
2017-08-18 16:52:05 -07:00
|
|
|
|
2016-12-29 23:39:44 -08:00
|
|
|
#ifndef POOL_H
|
|
|
|
#define POOL_H
|
|
|
|
|
2017-01-27 16:00:19 -08:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-12-29 23:39:44 -08:00
|
|
|
#include <stddef.h> /* size_t */
|
2018-01-18 14:39:51 -08:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
|
|
|
|
#include "zstd.h"
|
2016-12-29 23:39:44 -08:00
|
|
|
|
|
|
|
typedef struct POOL_ctx_s POOL_ctx;
|
|
|
|
|
|
|
|
/*! POOL_create() :
|
2017-07-11 14:14:07 -07:00
|
|
|
* 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.
|
2016-12-29 23:39:44 -08:00
|
|
|
*/
|
2018-01-18 14:39:51 -08:00
|
|
|
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize);
|
2016-12-29 23:39:44 -08:00
|
|
|
|
2018-01-18 14:39:51 -08:00
|
|
|
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem);
|
2017-08-24 17:01:41 -07:00
|
|
|
|
2016-12-29 23:39:44 -08:00
|
|
|
/*! POOL_free() :
|
|
|
|
Free a thread pool returned by POOL_create().
|
|
|
|
*/
|
2018-01-18 14:39:51 -08:00
|
|
|
void POOL_free(POOL_ctx* ctx);
|
2016-12-29 23:39:44 -08:00
|
|
|
|
2017-06-01 17:56:14 -07:00
|
|
|
/*! POOL_sizeof() :
|
|
|
|
return memory usage of pool returned by POOL_create().
|
|
|
|
*/
|
2018-01-18 14:39:51 -08:00
|
|
|
size_t POOL_sizeof(POOL_ctx* ctx);
|
2017-06-01 17:56:14 -07:00
|
|
|
|
2016-12-29 23:39:44 -08:00
|
|
|
/*! POOL_function :
|
|
|
|
The function type that can be added to a thread pool.
|
|
|
|
*/
|
2018-01-18 14:39:51 -08:00
|
|
|
typedef void (*POOL_function)(void*);
|
2016-12-29 23:39:44 -08:00
|
|
|
/*! POOL_add_function :
|
|
|
|
The function type for a generic thread pool add function.
|
|
|
|
*/
|
2018-01-18 14:39:51 -08:00
|
|
|
typedef void (*POOL_add_function)(void*, POOL_function, void*);
|
2016-12-29 23:39:44 -08:00
|
|
|
|
|
|
|
/*! POOL_add() :
|
2018-01-18 14:39:51 -08:00
|
|
|
Add the job `function(opaque)` to the thread pool. `ctx` must be valid.
|
2016-12-29 23:39:44 -08:00
|
|
|
Possibly blocks until there is room in the queue.
|
2016-12-31 16:10:47 -08:00
|
|
|
Note : The function may be executed asynchronously, so `opaque` must live until the function has been completed.
|
2016-12-29 23:39:44 -08:00
|
|
|
*/
|
2018-01-18 14:39:51 -08:00
|
|
|
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);
|
2016-12-29 23:39:44 -08:00
|
|
|
|
2017-01-27 16:00:19 -08:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-29 23:39:44 -08:00
|
|
|
#endif
|