MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / thdpool_create

Function thdpool_create

util/thdpool.c:219–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219struct thdpool *thdpool_create(const char *name, size_t per_thread_data_sz)
220{
221 struct thdpool *pool;
222
223 pool = calloc(1, sizeof(struct thdpool));
224 if (!pool) {
225 logmsg(LOGMSG_ERROR, "%s: out of memory\n", __func__);
226 return NULL;
227 }
228 pool->name = strdup(name);
229 if (!pool->name) {
230 logmsg(LOGMSG_ERROR, "%s: strdup out of memory\n", __func__);
231 free(pool);
232 return NULL;
233 }
234 pool->pool = pool_init(sizeof(struct workitem), 0);
235 if (!pool->pool) {
236 logmsg(LOGMSG_ERROR, "%s: pool_init failed\n", __func__);
237 free(pool->name);
238 free(pool);
239 return NULL;
240 }
241#ifdef MONITOR_STACK
242 pool->stack_alloc =
243 comdb2ma_create_with_scope(0, 0, "stack", pool->name, 1);
244 if (pool->stack_alloc == NULL) {
245 logmsg(LOGMSG_ERROR, "%s: comdb2ma_create failed\n", __func__);
246 free(pool->name);
247 free(pool);
248 return NULL;
249 }
250#endif
251 listc_init(&pool->thdlist, offsetof(struct thd, thdlist_linkv));
252 listc_init(&pool->freelist, offsetof(struct thd, freelist_linkv));
253 listc_init(&pool->queue, offsetof(struct workitem, linkv));
254
255 Pthread_mutex_init(&pool->mutex, NULL);
256 Pthread_attr_init(&pool->attrs);
257 Pthread_attr_setstacksize(&pool->attrs, DEFAULT_THD_STACKSZ);
258 Pthread_attr_setdetachstate(&pool->attrs, PTHREAD_CREATE_DETACHED);
259
260 /* 1 meg default mem per thread for thread_malloc() */
261 pool->mem_sz = 1 * 1024 * 1024;
262
263 pool->per_thread_data_sz = per_thread_data_sz;
264 pool->longwaitms = 500;
265 pool->wait = 0;
266 pool->exit_on_create_fail = 1;
267 pool->dump_on_full = 0;
268 pool->stack_sz = DEFAULT_THD_STACKSZ;
269
270 Pthread_cond_init(&pool->wait_for_thread, NULL);
271
272 Pthread_mutex_lock(&pool_list_lk);
273 pthread_once(&init_pool_list_once, init_pool_list);
274 listc_abl(&threadpools, pool);
275 Pthread_mutex_unlock(&pool_list_lk);
276

Callers 9

pgcompact_thdpool_initFunction · 0.85
udppfault_thdpool_initFunction · 0.85
__dbenv_openFunction · 0.85
init_trickle_threadsFunction · 0.85
mainFunction · 0.85
osqlpfthdpool_initFunction · 0.85
create_sql_poolFunction · 0.85
init_verify_thdpoolFunction · 0.85
appsock_initFunction · 0.85

Calls 8

callocFunction · 0.85
freeFunction · 0.85
pool_initFunction · 0.85
listc_initFunction · 0.85
listc_ablFunction · 0.85
logmsgFunction · 0.70
strdupFunction · 0.50

Tested by 1

mainFunction · 0.68