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 +++++++++++++++++++++++++- src/pacman/conf.c | 20 ++++++++++++++++++++ src/pacman/conf.h | 1 + 5 files changed, 51 insertions(+), 2 deletions(-) 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: */ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index a283d7f4..59c38696 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -606,6 +606,26 @@ static int _parse_options(const char *key, char *value, return 1; } FREELIST(values); + } else if(strcmp(key, "Threads") == 0) { + unsigned long threads; + char *endptr; + + if(!(alpm_capabilities() & ALPM_CAPABILITY_THREADS)) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: '%s' option invalid, no thread support\n"), + file, linenum, "Threads"); + return 1; + } + + threads = strtoul(value, &endptr, 10); + if(*endptr != '\0' || threads < 0) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: invalid value for '%s' : '%s'\n"), + file, linenum, "Threads", value); + return 1; + } + config->threads = threads; + pm_printf(ALPM_LOG_DEBUG, "config: Threads = %f\n", threads); } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 53b44be6..23cb1e52 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -126,6 +126,7 @@ typedef struct __config_t { alpm_list_t *noextract; alpm_list_t *overwrite_files; char *xfercommand; + unsigned int threads; /* our connection to libalpm */ alpm_handle_t *handle; -- cgit v1.2.3-24-g4f1b