From f20aac8bedd585352cabdff8ec4ba015efb08a12 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Wed, 2 Aug 2017 10:57:05 +0100 Subject: [PATCH] Only free tp->threads when allocated, set the mapper function for logging when only using one thread --- src/threadpool.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/threadpool.c b/src/threadpool.c index f6476e2a92..465756f71d 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -268,6 +268,7 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function, if (tp->num_threads == 1) { map_function(map_data, N, extra_data); #ifdef SWIFT_DEBUG_THREADPOOL + tp->map_function = map_function; threadpool_log(tp, 0, N, tic, getticks()); #endif return; @@ -330,10 +331,11 @@ void threadpool_clean(struct threadpool *tp) { if (pthread_barrier_destroy(&tp->wait_barrier) != 0 || pthread_barrier_destroy(&tp->run_barrier) != 0) error("Failed to destroy threadpool barriers."); + + /* Clean up memory. */ + free(tp->threads); } - /* Clean up memory. */ - free(tp->threads); #ifdef SWIFT_DEBUG_THREADPOOL for (int k = 0; k < tp->num_threads; k++) { free(tp->logs[k].log); -- GitLab