summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-01-22 22:23:56 +0100
committerAndrew Gregory <andrew.gregory.8@gmail.com>2017-05-11 06:45:30 +0200
commit153d3e1a68a071dfcee535a24d23fa1c054fe70a (patch)
tree1fcdea88f4a12463b0eb50850b5ef141b81976e6
parentbfce4c04da643ba2b4ca8733b7788ab72729c7b3 (diff)
downloadpacman-153d3e1a68a071dfcee535a24d23fa1c054fe70a.tar.gz
pacman-153d3e1a68a071dfcee535a24d23fa1c054fe70a.tar.xz
run_threaded: run function in main thread
reduces the number of threads created.
-rw-r--r--lib/libalpm/handle.c19
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);