Loading...
Searching...
No Matches
as_thread_pool.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2022 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <aerospike/as_std.h>
20#include <citrusleaf/cf_queue.h>
21#include <pthread.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27//---------------------------------
28// Types
29//---------------------------------
30
31/**
32 * @private
33 * Task function callback.
34 */
35typedef void (*as_task_fn)(void* user_data);
36
37/**
38 * @private
39 * Thread finalization function callback.
40 */
41typedef void (*as_fini_fn)(void);
42
43/**
44 * @private
45 * Thread pool.
46 */
47typedef struct as_thread_pool_s {
48 pthread_t* threads;
49 cf_queue* dispatch_queue;
51 uint32_t thread_size;
53
54//---------------------------------
55// Functions
56//---------------------------------
57
58/**
59 * @private
60 * Initialize variable task thread pool and start thread_size threads.
61 * Multiple task types can be handled in variable task thread pools.
62 *
63 * Returns:
64 * 0 : Success
65 * -1 : Failed to initialize mutex lock
66 * -2 : Failed to lock mutex
67 * -3 : Some threads failed to start
68 */
69int
70as_thread_pool_init(as_thread_pool* pool, uint32_t thread_size);
71
72/**
73 * @private
74 * Queue a variable task onto thread pool.
75 *
76 * Returns:
77 * 0 : Success
78 * -1 : No threads are running to process task.
79 * -2 : Failed to push task onto dispatch queue
80 */
81int
83
84/**
85 * @private
86 * Destroy thread pool.
87 *
88 * Returns:
89 * 0 : Success
90 * -1 : Failed to lock mutex
91 * -2 : Pool has already been closed
92 */
93int
95
96#ifdef __cplusplus
97} // end extern "C"
98#endif
void(* as_fini_fn)(void)
void(* as_task_fn)(void *user_data)
int as_thread_pool_queue_task(as_thread_pool *pool, as_task_fn task_fn, void *task)
int as_thread_pool_destroy(as_thread_pool *pool)
int as_thread_pool_init(as_thread_pool *pool, uint32_t thread_size)
uint32_t thread_size
cf_queue * dispatch_queue
pthread_t * threads
as_fini_fn fini_fn