# HG changeset patch # User Olaf Wintermann # Date 1652525159 -7200 # Node ID f45e962edf457d99e76f15a4909a7ee2ab579bfc # Parent eebc3d32c7c132b047d872174fac4cb6ad565503 add separate threadpool_start function for creating initial threadpool threads diff -r eebc3d32c7c1 -r f45e962edf45 src/server/daemon/sessionhandler.c --- a/src/server/daemon/sessionhandler.c Sat May 14 11:18:14 2022 +0200 +++ b/src/server/daemon/sessionhandler.c Sat May 14 12:45:59 2022 +0200 @@ -126,6 +126,7 @@ SessionHandler* create_basic_session_handler() { BasicSessionHandler *handler = malloc(sizeof(BasicSessionHandler)); handler->threadpool = threadpool_new(4, 8); + threadpool_start(handler->threadpool); // TODO: handle error handler->sh.enqueue_connection = basic_enq_conn; handler->sh.keep_alive = basic_keep_alive; handler->sh.create_iostream = create_connection_iostream; diff -r eebc3d32c7c1 -r f45e962edf45 src/server/daemon/threadpools.c --- a/src/server/daemon/threadpools.c Sat May 14 11:18:14 2022 +0200 +++ b/src/server/daemon/threadpools.c Sat May 14 12:45:59 2022 +0200 @@ -63,7 +63,12 @@ } else { threadpool_t *tp = threadpool_new(cfg->min_threads, cfg->max_threads); - int ret = ucx_map_sstr_put(thread_pool_map, name, tp); + int ret = 0; + if(!threadpool_start(tp)) { + ret = ucx_map_sstr_put(thread_pool_map, name, tp); + } else { + ret = 1; + } if(ret == 0) { num_thrpools++; diff -r eebc3d32c7c1 -r f45e962edf45 src/server/public/nsapi.h --- a/src/server/public/nsapi.h Sat May 14 11:18:14 2022 +0200 +++ b/src/server/public/nsapi.h Sat May 14 12:45:59 2022 +0200 @@ -1600,6 +1600,7 @@ // threadpool threadpool_t* threadpool_new(int min, int max); +int threadpool_start(threadpool_t *pool); void* threadpool_func(void *data); threadpool_job* threadpool_get_job(threadpool_t *pool); void threadpool_run(threadpool_t *pool, job_callback_f func, void *data); diff -r eebc3d32c7c1 -r f45e962edf45 src/server/util/thrpool.c --- a/src/server/util/thrpool.c Sat May 14 11:18:14 2022 +0200 +++ b/src/server/util/thrpool.c Sat May 14 12:45:59 2022 +0200 @@ -47,18 +47,21 @@ pthread_mutex_init(&pool->queue_lock, NULL); pthread_mutex_init(&pool->avlbl_lock, NULL); - pthread_cond_init(&pool->available, NULL); + pthread_cond_init(&pool->available, NULL); + return pool; +} + +int threadpool_start(threadpool_t *pool) { /* create pool threads */ - for(int i=0;imin_threads;i++) { pthread_t t; if (pthread_create(&t, NULL, threadpool_func, pool) != 0) { - perror("Error: threadpool_new: pthread_create"); - return NULL; + perror("Error: threadpool_start: pthread_create"); + return 1; } } - - return pool; + return 0; } void* threadpool_func(void *data) {