diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2015-01-22 22:23:56 +0100 |
---|---|---|
committer | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-05-11 06:45:30 +0200 |
commit | 153d3e1a68a071dfcee535a24d23fa1c054fe70a (patch) | |
tree | 1fcdea88f4a12463b0eb50850b5ef141b81976e6 /lib/libalpm/handle.c | |
parent | bfce4c04da643ba2b4ca8733b7788ab72729c7b3 (diff) | |
download | pacman-153d3e1a68a071dfcee535a24d23fa1c054fe70a.tar.gz pacman-153d3e1a68a071dfcee535a24d23fa1c054fe70a.tar.xz |
run_threaded: run function in main thread
reduces the number of threads created.
Diffstat (limited to 'lib/libalpm/handle.c')
-rw-r--r-- | lib/libalpm/handle.c | 19 |
1 files 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); |