src/server/daemon/threadpools.c

branch
aio
changeset 190
1f73302461e0
parent 187
4384bfbb7e26
child 256
19259b6c5cf7
equal deleted inserted replaced
189:a2438f6d1e73 190:1f73302461e0
32 #include <ucx/map.h> 32 #include <ucx/map.h>
33 33
34 #include "threadpools.h" 34 #include "threadpools.h"
35 35
36 36
37 static UcxMap *thread_pool_map = NULL; 37 static UcxMap *thread_pool_map;
38 static int numthrpools = 0; 38 static int num_thrpools;
39 static UcxMap *io_pool_map;
40 static int num_iopools;
39 41
40 threadpool_t *default_thread_pool = NULL; 42 static threadpool_t *default_thread_pool;
43 static threadpool_t *last_thrpool_c;
41 44
42 threadpool_t *last_thrpool_c = NULL; 45 static threadpool_t *default_io_pool;
46 static threadpool_t *last_io_pool;
43 47
44 int create_threadpool(sstr_t name, ThreadPoolConfig *cfg) { 48 int create_threadpool(sstr_t name, ThreadPoolConfig *cfg) {
45 if(thread_pool_map == NULL) { 49 if(thread_pool_map == NULL) {
46 thread_pool_map = ucx_map_new(16); 50 thread_pool_map = ucx_map_new(16);
47 } 51 }
60 threadpool_t *tp = threadpool_new(cfg->min_threads, cfg->max_threads); 64 threadpool_t *tp = threadpool_new(cfg->min_threads, cfg->max_threads);
61 65
62 int ret = ucx_map_sstr_put(thread_pool_map, name, tp); 66 int ret = ucx_map_sstr_put(thread_pool_map, name, tp);
63 67
64 if(ret == 0) { 68 if(ret == 0) {
65 numthrpools++; 69 num_thrpools++;
66 last_thrpool_c = tp; 70 last_thrpool_c = tp;
71 if(!default_thread_pool) {
72 default_thread_pool = tp;
73 }
74 }
75
76 return ret;
77 }
78 }
79
80 int create_io_pool(sstr_t name, int numthreads) {
81 if(io_pool_map == NULL) {
82 io_pool_map = ucx_map_new(4);
83 }
84 threadpool_t *pool = ucx_map_sstr_get(io_pool_map, name);
85 if(pool) {
86 pool->min_threads = numthreads;
87 pool->max_threads = numthreads;
88 return 0;
89 } else {
90 threadpool_t *tp = threadpool_new(numthreads, numthreads);
91
92 int ret = ucx_map_sstr_put(io_pool_map, name, tp);
93
94 if(ret == 0) {
95 num_iopools++;
96 last_io_pool = tp;
97 if(!default_io_pool) {
98 default_io_pool = tp;
99 }
67 } 100 }
68 101
69 return ret; 102 return ret;
70 } 103 }
71 } 104 }
72 105
73 int check_thread_pool_cfg() { 106 int check_thread_pool_cfg() {
74 if(numthrpools > 0 ) { 107 if(num_thrpools == 0) {
75 if(default_thread_pool) { 108 ThreadPoolConfig cfg;
76 return 0; 109 cfg.min_threads = 4;
77 } else { 110 cfg.max_threads = 8;
78 default_thread_pool = last_thrpool_c; 111 cfg.queue_size = 64;
79 return 0; 112 cfg.stack_size = 262144;
113 if(create_threadpool(sstr("default"), &cfg)) {
114 return 1;
80 } 115 }
81 } 116 }
82 117
83 ThreadPoolConfig cfg; 118 if(num_iopools == 0) {
84 cfg.min_threads = 4; 119 if(create_io_pool(sstr("default"), 8)) {
85 cfg.max_threads = 8; 120 return 1;
86 cfg.queue_size = 64; 121 }
87 cfg.stack_size = 262144; 122 }
88 123
89 return create_threadpool(sstr("default"), &cfg); 124 return 0;
90 } 125 }
91 126
92 threadpool_t* get_default_threadpool() { 127 threadpool_t* get_default_threadpool() {
93 return default_thread_pool; 128 return default_thread_pool;
94 } 129 }
95 130
96 threadpool_t* get_threadpool(sstr_t name) { 131 threadpool_t* get_threadpool(sstr_t name) {
97 return ucx_map_sstr_get(thread_pool_map, name); 132 return ucx_map_sstr_get(thread_pool_map, name);
98 } 133 }
134
135 threadpool_t* get_default_iopool() {
136 return default_io_pool;
137 }
138
139 threadpool_t* get_iopool(sstr_t name) {
140 return ucx_map_sstr_get(io_pool_map, name);
141 }

mercurial