Commit 190a201e authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'threadpool_map' into 'master'

if the threadpool is initialized with a single thread, don't bother spawning a r…

…unner, just run in the threadpool_map callee, which is blocked.

See #252.

See merge request !293
parents 1ce1015d f36878f3
......@@ -90,6 +90,10 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
/* Initialize the thread counters. */
tp->num_threads = num_threads;
tp->num_threads_waiting = 0;
/* If there is only a single thread, do nothing more as of here as
we will just do work in the (blocked) calling thread. */
if (num_threads == 1) return;
/* Init the threadpool mutexes. */
if (pthread_mutex_init(&tp->thread_mutex, NULL) != 0)
......@@ -143,6 +147,12 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
void threadpool_map(struct threadpool *tp, threadpool_map_function map_function,
void *map_data, size_t N, int stride, int chunk,
void *extra_data) {
/* If we just have a single thread, call the map function directly. */
if (tp->num_threads == 1) {
map_function(map_data, N, extra_data);
/* Set the map data and signal the threads. */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment