/** * Construct a new thread pool with <b>n</b> worker threads, configured to * send their output to <b>replyqueue</b>. The threads' states will be * constructed with the <b>new_thread_state_fn</b> call, receiving <b>arg</b> * as its argument. When the threads close, they will call * <b>free_thread_state_fn</b> on their states. */ threadpool_t * threadpool_new(int n_threads, replyqueue_t *replyqueue, void *(*new_thread_state_fn)(void*), void (*free_thread_state_fn)(void*), void *arg) { threadpool_t *pool; pool = tor_malloc_zero(sizeof(threadpool_t)); tor_mutex_init_nonrecursive(&pool->lock); tor_cond_init(&pool->condition); TOR_TAILQ_INIT(&pool->work); pool->new_thread_state_fn = new_thread_state_fn; pool->new_thread_state_arg = arg; pool->free_thread_state_fn = free_thread_state_fn; pool->reply_queue = replyqueue; if (threadpool_start_threads(pool, n_threads) < 0) { tor_mutex_uninit(&pool->lock); tor_free(pool); return NULL; } return pool; }
/** Release all storage and system resources held by <b>m</b>. */ void tor_mutex_free(tor_mutex_t *m) { if (!m) return; tor_mutex_uninit(m); tor_free(m); }
/** Uninstall crash handlers. */ static void remove_bt_handler(void) { tor_mutex_uninit(&cb_buf_mutex); }