src/server/daemon/threadpools.c

changeset 385
a1f4cb076d2f
parent 357
f45e962edf45
child 415
d938228c382e
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
43 static threadpool_t *last_thrpool_c; 43 static threadpool_t *last_thrpool_c;
44 44
45 static threadpool_t *default_io_pool; 45 static threadpool_t *default_io_pool;
46 static threadpool_t *last_io_pool; 46 static threadpool_t *last_io_pool;
47 47
48 int create_threadpool(sstr_t name, ThreadPoolConfig *cfg) { 48 int create_threadpool(scstr_t name, ThreadPoolConfig *cfg) {
49 if(thread_pool_map == NULL) { 49 if(thread_pool_map == NULL) {
50 thread_pool_map = ucx_map_new(16); 50 thread_pool_map = ucx_map_new(16);
51 } 51 }
52 52
53 threadpool_t *pool = ucx_map_sstr_get(thread_pool_map, name); 53 threadpool_t *pool = ucx_map_sstr_get(thread_pool_map, name);
61 } 61 }
62 return 0; 62 return 0;
63 } else { 63 } else {
64 threadpool_t *tp = threadpool_new(cfg->min_threads, cfg->max_threads); 64 threadpool_t *tp = threadpool_new(cfg->min_threads, cfg->max_threads);
65 65
66 int ret = ucx_map_sstr_put(thread_pool_map, name, tp); 66 int ret = 0;
67 if(!threadpool_start(tp)) {
68 ret = ucx_map_sstr_put(thread_pool_map, name, tp);
69 } else {
70 ret = 1;
71 }
67 72
68 if(ret == 0) { 73 if(ret == 0) {
69 num_thrpools++; 74 num_thrpools++;
70 last_thrpool_c = tp; 75 last_thrpool_c = tp;
71 if(!default_thread_pool) { 76 if(!default_thread_pool) {
75 80
76 return ret; 81 return ret;
77 } 82 }
78 } 83 }
79 84
80 int create_io_pool(sstr_t name, int numthreads) { 85 int create_io_pool(scstr_t name, int numthreads) {
81 if(io_pool_map == NULL) { 86 if(io_pool_map == NULL) {
82 io_pool_map = ucx_map_new(4); 87 io_pool_map = ucx_map_new(4);
83 } 88 }
84 threadpool_t *pool = ucx_map_sstr_get(io_pool_map, name); 89 threadpool_t *pool = ucx_map_sstr_get(io_pool_map, name);
85 if(pool) { 90 if(pool) {
108 ThreadPoolConfig cfg; 113 ThreadPoolConfig cfg;
109 cfg.min_threads = 4; 114 cfg.min_threads = 4;
110 cfg.max_threads = 8; 115 cfg.max_threads = 8;
111 cfg.queue_size = 64; 116 cfg.queue_size = 64;
112 cfg.stack_size = 262144; 117 cfg.stack_size = 262144;
113 if(create_threadpool(sstr("default"), &cfg)) { 118 if(create_threadpool(SC("default"), &cfg)) {
114 return 1; 119 return 1;
115 } 120 }
116 } 121 }
117 122
118 if(num_iopools == 0) { 123 if(num_iopools == 0) {
119 if(create_io_pool(sstr("default"), 8)) { 124 if(create_io_pool(SC("default"), 8)) {
120 return 1; 125 return 1;
121 } 126 }
122 } 127 }
123 128
124 return 0; 129 return 0;

mercurial