summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-01-22 18:21:26 +0100
committerAndrew Gregory <andrew.gregory.8@gmail.com>2017-05-11 06:45:30 +0200
commit286ff380575699e743f4b595fb020cb37b7d5e8c (patch)
tree5e94aa7b33b7aba005c5f30191fca79d484d83fe
parenta391c54eb3df2d8de32c6ce4d5e2b05c46dbf487 (diff)
downloadpacman-286ff380575699e743f4b595fb020cb37b7d5e8c.tar.gz
pacman-286ff380575699e743f4b595fb020cb37b7d5e8c.tar.xz
add threads option
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
-rw-r--r--lib/libalpm/alpm.c3
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/handle.c26
-rw-r--r--src/pacman/conf.c20
-rw-r--r--src/pacman/conf.h1
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
@@ -164,6 +164,9 @@ int SYMEXPORT alpm_capabilities(void)
#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;