forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththdpool.h
125 lines (98 loc) · 4.38 KB
/
thdpool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
Copyright 2015 Bloomberg Finance L.P.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* Generic thread pool for comdb2. This implementation will grow the pool
* as much as it needs to in order to meet demand.
*/
#ifndef INC__THDPOOL_H
#define INC__THDPOOL_H
// comdb2ar is c++
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
struct thdpool;
enum thdpool_ioctl_op { THD_RUN, THD_FREE };
/* Set some sane defaults for stacksize */
enum {
#if defined(_LINUX_SOURCE)
DEFAULT_THD_STACKSZ = 1048576
#elif defined(_SUN_SOURCE)
DEFAULT_THD_STACKSZ = 1048576
#elif defined(_IBM_SOURCE)
DEFAULT_THD_STACKSZ = 163840
#elif defined(_HP_SOURCE)
DEFAULT_THD_STACKSZ = 524288
#endif
};
typedef void (*thdpool_work_fn)(struct thdpool *pool, void *work, void *thddata,
int op);
typedef void (*thdpool_thdinit_fn)(struct thdpool *pool, void *thddata);
typedef void (*thdpool_thddelt_fn)(struct thdpool *pool, void *thddata);
struct thdpool *thdpool_create(const char *name, size_t per_thread_data_sz);
void thdpool_set_stack_size(struct thdpool *pool, size_t sz_bytes);
void thdpool_set_init_fn(struct thdpool *pool, thdpool_thdinit_fn init_fn);
void thdpool_set_delt_fn(struct thdpool *pool, thdpool_thddelt_fn delt_fn);
void thdpool_set_linger(struct thdpool *pool, unsigned lingersecs);
void thdpool_set_minthds(struct thdpool *pool, unsigned minnthd);
void thdpool_set_maxthds(struct thdpool *pool, unsigned minnthd);
void thdpool_set_maxqueue(struct thdpool *pool, unsigned maxqueue);
void thdpool_set_longwaitms(struct thdpool *pool, unsigned longwaitms);
void thdpool_set_maxqueueagems(struct thdpool *pool, unsigned maxqueueagems);
void thdpool_set_maxqueueoverride(struct thdpool *pool,
unsigned maxqueueoverride);
void thdpool_set_mem_size(struct thdpool *pool, size_t sz_bytes);
void thdpool_print_stats(FILE *fh, struct thdpool *pool);
int thdpool_enqueue(struct thdpool *pool, thdpool_work_fn work_fn, void *work,
int queue_override, char *persistent_info);
void thdpool_stop(struct thdpool *pool);
void thdpool_resume(struct thdpool *pool);
void thdpool_set_exit(struct thdpool *pool);
void thdpool_set_wait(struct thdpool *pool, int wait);
void thdpool_process_message(struct thdpool *pool, char *line, int lline,
int st);
char *thdpool_get_name(struct thdpool *pool);
int thdpool_get_status(struct thdpool *pool);
int thdpool_get_nthds(struct thdpool *pool);
int thdpool_get_nfreethds(struct thdpool *pool);
int thdpool_get_maxthds(struct thdpool *pool);
int thdpool_get_peaknthds(struct thdpool *pool);
int thdpool_get_creates(struct thdpool *pool);
int thdpool_get_exits(struct thdpool *pool);
int thdpool_get_passed(struct thdpool *pool);
int thdpool_get_enqueued(struct thdpool *pool);
int thdpool_get_dequeued(struct thdpool *pool);
int thdpool_get_timeouts(struct thdpool *pool);
int thdpool_get_failed_dispatches(struct thdpool *pool);
int thdpool_get_minnthd(struct thdpool *pool);
int thdpool_get_maxnthd(struct thdpool *pool);
int thdpool_get_peakqueue(struct thdpool *pool);
int thdpool_get_maxqueue(struct thdpool *pool);
int thdpool_get_nqueuedworks(struct thdpool *pool);
int thdpool_get_longwaitms(struct thdpool *pool);
int thdpool_get_lingersecs(struct thdpool *pool);
int thdpool_get_stacksz(struct thdpool *pool);
int thdpool_get_maxqueueoverride(struct thdpool *pool);
int thdpool_get_maxqueueagems(struct thdpool *pool);
int thdpool_get_exit_on_create_fail(struct thdpool *pool);
int thdpool_get_dump_on_full(struct thdpool *pool);
void thdpool_list_pools(void);
void thdpool_command_to_all(char *line, int lline, int st);
void thdpool_set_dump_on_full(struct thdpool *pool, int onoff);
int thdpool_lock(struct thdpool *pool);
int thdpool_unlock(struct thdpool *pool);
struct thdpool *thdpool_next_pool(struct thdpool *pool);
#ifdef __cplusplus
}
#endif
#endif /* INC__THDPOOL_H */