From bfce4c04da643ba2b4ca8733b7788ab72729c7b3 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 22 Jan 2015 15:45:52 -0500 Subject: add --threads option --- src/pacman/conf.c | 6 +++++- src/pacman/conf.h | 3 ++- src/pacman/pacman.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 93473465..83093d57 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -105,7 +105,7 @@ config_t *config_new(void) newconfig->logmask = ALPM_LOG_ERROR | ALPM_LOG_WARNING; newconfig->configfile = strdup(CONFFILE); newconfig->deltaratio = 0.0; - newconfig->threads = 1; + newconfig->threads = 0; if(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) { newconfig->siglevel = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL | ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; @@ -611,6 +611,10 @@ static int _parse_options(const char *key, char *value, unsigned long threads; char *endptr; + if(config->threads != 0) { + return 0; + } + if(!(alpm_capabilities() & ALPM_CAPABILITY_THREADS)) { pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: '%s' option invalid, no thread support\n"), diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 23cb1e52..4b076ffd 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -210,7 +210,8 @@ enum { OP_DOWNLOADONLY, OP_REFRESH, OP_ASSUMEINSTALLED, - OP_DISABLEDLTIMEOUT + OP_DISABLEDLTIMEOUT, + OP_THREADS }; /* clean method */ diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 8c7f715e..ae63978e 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -368,6 +368,24 @@ static int parsearg_op(int opt, int dryrun) return 0; } +static void set_threads(const char *value) +{ + unsigned long threads; + char *endptr; + + if(!(alpm_capabilities() & ALPM_CAPABILITY_THREADS)) { + pm_printf(ALPM_LOG_ERROR, + _("'%s' option invalid, no thread support\n"), "--threads"); + } + + threads = strtoul(value, &endptr, 10); + if(*endptr != '\0' || threads < 1 || threads > UINT_MAX) { + pm_printf(ALPM_LOG_ERROR, + _("invalid value for '%s' : '%s'\n"), "--threads", value); + } + config->threads = threads; +} + /** Helper functions for parsing command-line arguments. * @param opt Keycode returned by getopt_long * @return 0 on success, 1 on failure @@ -459,6 +477,8 @@ static int parsearg_global(int opt) break; case OP_DISABLEDLTIMEOUT: config->disable_dl_timeout = 1; + case OP_THREADS: + set_threads(optarg); break; case OP_VERBOSE: case 'v': @@ -963,6 +983,7 @@ static int parseargs(int argc, char *argv[]) {"dbonly", no_argument, 0, OP_DBONLY}, {"color", required_argument, 0, OP_COLOR}, {"disable-download-timeout", no_argument, 0, OP_DISABLEDLTIMEOUT}, + {"threads", required_argument, 0, OP_THREADS}, {0, 0, 0, 0} }; -- cgit v1.2.3-24-g4f1b