Skip to content
Snippets Groups Projects
Commit b9232db9 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

add an initial implementation.

parent d7cd3ff8
No related branches found
No related tags found
1 merge request!176Tasks cleanup
......@@ -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 \
......
......@@ -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 */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment