Skip to content
Snippets Groups Projects

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

Merged Pedro Gonnet requested to merge threadpool_map into master
+ 10
0
Compare changes
  • Side-by-side
  • Inline
+ 10
0
@@ -90,6 +90,10 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
@@ -90,6 +90,10 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
/* Initialize the thread counters. */
/* Initialize the thread counters. */
tp->num_threads = num_threads;
tp->num_threads = num_threads;
tp->num_threads_waiting = 0;
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. */
/* Init the threadpool mutexes. */
if (pthread_mutex_init(&tp->thread_mutex, NULL) != 0)
if (pthread_mutex_init(&tp->thread_mutex, NULL) != 0)
@@ -143,6 +147,12 @@ void threadpool_init(struct threadpool *tp, int num_threads) {
@@ -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 threadpool_map(struct threadpool *tp, threadpool_map_function map_function,
void *map_data, size_t N, int stride, int chunk,
void *map_data, size_t N, int stride, int chunk,
void *extra_data) {
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);
 
return;
 
}
/* Set the map data and signal the threads. */
/* Set the map data and signal the threads. */
pthread_mutex_lock(&tp->thread_mutex);
pthread_mutex_lock(&tp->thread_mutex);
Loading