summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/handle.c')
-rw-r--r--lib/libalpm/handle.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index c58718fc..1a8a4344 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -48,6 +48,7 @@ alpm_handle_t *_alpm_handle_new(void)
handle->lockfd = -1;
#ifdef HAVE_PTHREAD
+ handle->threads = 4;
pthread_mutex_init(&(handle->tlock_cb), NULL);
pthread_mutex_init(&(handle->tlock_log), NULL);
pthread_mutex_init(&(handle->tlock_task), NULL);
@@ -905,4 +906,25 @@ void _alpm_set_errno(alpm_handle_t *handle, alpm_errno_t err) {
#endif
}
+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);
+ }
+#else
+ function(arg);
+#endif
+}
+
/* vim: set noet: */