diff --git a/src/Makefile.am b/src/Makefile.am index f50f5574d16227cc925866596ad1766ee4f5a171..322a4823527f078da9142229c6e2b8d100379610 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,14 +36,15 @@ endif include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ engine.h swift.h serial_io.h timers.h debug.h scheduler.h proxy.h parallel_io.h \ common_io.h single_io.h multipole.h map.h tools.h partition.h clocks.h parser.h \ - physical_constants.h physical_constants_cgs.h potentials.h version.h hydro_properties.h + physical_constants.h physical_constants_cgs.h potentials.h version.h \ + hydro_properties.h threadpool.h # Common source files AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ serial_io.c timers.c debug.c scheduler.c proxy.c parallel_io.c \ units.c common_io.c single_io.c multipole.c version.c map.c \ kernel_hydro.c kernel_gravity.c tools.c part.c partition.c clocks.c parser.c \ - physical_constants.c potentials.c hydro_properties.c + physical_constants.c potentials.c hydro_properties.c threadpool.c # Include files for distribution, not installation. nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ diff --git a/src/threadpool.h b/src/threadpool.h index a26eae0130287e404f43a99c10dfda4280f24e30..eb028b9162a9a231291d06854de0c7be0db8b71a 100644 --- a/src/threadpool.h +++ b/src/threadpool.h @@ -25,6 +25,9 @@ /* Some standard headers. */ #include <pthread.h> +/* Function type for mappings. */ +typedef void (*threadpool_map_function)(void *map_data, void *extra_data); + /* Data of a threadpool. */ struct threadpool { @@ -35,17 +38,21 @@ struct threadpool { pthread_t *threads; /* This is where threads go to rest. */ - pthread_mutex_t sleep_mutex; - pthread_cond_t sleep_cond; - + pthread_mutex_t control_mutex, thread_mutex; + pthread_cond_t control_cond, thread_cond; + /* Current map data and count. */ void *map_data; size_t map_data_count, map_data_size, map_data_stride; + threadpool_map_function map_function; + + /* Counter for the number of threads that are done. */ + int num_threads_done; }; /* Function prototypes. */ void threadpool_init(struct threadpool *tp, int num_threads); -void threadpool_map(struct threadpool *tp, void *map_data, size_t N, int stride, - void *extra_data); +void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, + void *map_data, size_t N, int stride, void *extra_data); #endif /* SWIFT_THREADPOOL_H */