From 153d3e1a68a071dfcee535a24d23fa1c054fe70a Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 22 Jan 2015 16:23:56 -0500 Subject: run_threaded: run function in main thread reduces the number of threads created. --- lib/libalpm/handle.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 43418d94..bb1cc219 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -907,17 +907,14 @@ void _alpm_run_threaded(alpm_handle_t *handle, void *(*function) (void *), void *arg) { #ifdef HAVE_PTHREAD - if(handle->threads > 1) { - pthread_t threads[handle->threads]; - int idx; - for(idx = 0; idx < handle->threads; idx++) { - pthread_create(&threads[idx], NULL, function, arg); - } - for(idx = 0; idx < handle->threads; idx++) { - pthread_join(threads[idx], NULL); - } - } else { - function(arg); + pthread_t threads[handle->threads - 1]; + int idx; + for(idx = 0; idx < handle->threads - 1; idx++) { + pthread_create(&threads[idx], NULL, function, arg); + } + function(arg); + for(idx = 0; idx < handle->threads - 1; idx++) { + pthread_join(threads[idx], NULL); } #else function(arg); -- cgit v1.2.3-24-g4f1b