Sat, 14 May 2022 12:45:59 +0200
add separate threadpool_start function for creating initial threadpool threads
--- 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;
--- 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++;
--- 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);
--- 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;i<min;i++) { + for(int i=0;i<pool->min_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) {