From 286ff380575699e743f4b595fb020cb37b7d5e8c Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 22 Jan 2015 12:21:26 -0500 Subject: add threads option Signed-off-by: Andrew Gregory --- lib/libalpm/alpm.c | 3 +++ lib/libalpm/alpm.h | 3 ++- lib/libalpm/handle.c | 26 +++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 552c1ad7..d1e9d6f3 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -163,6 +163,9 @@ int SYMEXPORT alpm_capabilities(void) #endif #ifdef HAVE_LIBGPGME | ALPM_CAPABILITY_SIGNATURES +#endif +#ifdef HAVE_PTHREAD + | ALPM_CAPABILITY_THREADS #endif | 0; } diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 664399c0..ae94a43e 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1630,7 +1630,8 @@ int alpm_unlock(alpm_handle_t *handle); enum alpm_caps { ALPM_CAPABILITY_NLS = (1 << 0), ALPM_CAPABILITY_DOWNLOADER = (1 << 1), - ALPM_CAPABILITY_SIGNATURES = (1 << 2) + ALPM_CAPABILITY_SIGNATURES = (1 << 2), + ALPM_CAPABILITY_THREADS = (1 << 3) }; const char *alpm_version(void); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 1a8a4344..67b28db5 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -48,7 +48,7 @@ alpm_handle_t *_alpm_handle_new(void) handle->lockfd = -1; #ifdef HAVE_PTHREAD - handle->threads = 4; + handle->threads = 1; pthread_mutex_init(&(handle->tlock_cb), NULL); pthread_mutex_init(&(handle->tlock_log), NULL); pthread_mutex_init(&(handle->tlock_task), NULL); @@ -927,4 +927,28 @@ void _alpm_run_threaded(alpm_handle_t *handle, #endif } +int SYMEXPORT alpm_option_set_thread_count(alpm_handle_t *handle, + unsigned int threads) +{ + CHECK_HANDLE(handle, return -1); +#ifdef HAVE_PTHREAD + handle->threads = threads; +#else + if(threads > 1) { + RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); + } +#endif + return 0; +} + +unsigned int SYMEXPORT alpm_option_get_thread_count(alpm_handle_t *handle) +{ + CHECK_HANDLE(handle, return -1); +#ifdef HAVE_PTHREAD + return handle->threads; +#else + return 1; +#endif +} + /* vim: set noet: */ -- cgit v1.2.3-24-g4f1b