Import zstd 1.1.4
[freebsd.git] / lib / common / pool.h
1 /**
2  * Copyright (c) 2016-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  */
9 #ifndef POOL_H
10 #define POOL_H
11
12 #if defined (__cplusplus)
13 extern "C" {
14 #endif
15
16
17 #include <stddef.h>   /* size_t */
18
19 typedef struct POOL_ctx_s POOL_ctx;
20
21 /*! POOL_create() :
22     Create a thread pool with at most `numThreads` threads.
23     `numThreads` must be at least 1.
24     The maximum number of queued jobs before blocking is `queueSize`.
25     `queueSize` must be at least 1.
26     @return : The POOL_ctx pointer on success else NULL.
27 */
28 POOL_ctx *POOL_create(size_t numThreads, size_t queueSize);
29
30 /*! POOL_free() :
31     Free a thread pool returned by POOL_create().
32 */
33 void POOL_free(POOL_ctx *ctx);
34
35 /*! POOL_function :
36     The function type that can be added to a thread pool.
37 */
38 typedef void (*POOL_function)(void *);
39 /*! POOL_add_function :
40     The function type for a generic thread pool add function.
41 */
42 typedef void (*POOL_add_function)(void *, POOL_function, void *);
43
44 /*! POOL_add() :
45     Add the job `function(opaque)` to the thread pool.
46     Possibly blocks until there is room in the queue.
47     Note : The function may be executed asynchronously, so `opaque` must live until the function has been completed.
48 */
49 void POOL_add(void *ctx, POOL_function function, void *opaque);
50
51
52 #if defined (__cplusplus)
53 }
54 #endif
55
56 #endif