From 2e63d6aa7fcdfd89f02758f02f5799a291405b40 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 22 Jan 2015 00:29:53 -0500 Subject: make pm_errno thread-local Signed-off-by: Andrew Gregory --- lib/libalpm/handle.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/handle.c') diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 941bdd25..c58718fc 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -50,8 +50,13 @@ alpm_handle_t *_alpm_handle_new(void) #ifdef HAVE_PTHREAD pthread_mutex_init(&(handle->tlock_cb), NULL); pthread_mutex_init(&(handle->tlock_log), NULL); + pthread_mutex_init(&(handle->tlock_task), NULL); + pthread_key_create(&(handle->tkey_err), free); + pthread_setspecific(handle->tkey_err, malloc(sizeof(int))); #endif + _alpm_set_errno(handle, 0); + return handle; } @@ -539,7 +544,7 @@ int SYMEXPORT alpm_option_set_logfile(alpm_handle_t *handle, const char *logfile CHECK_HANDLE(handle, return -1); if(!logfile) { - handle->pm_errno = ALPM_ERR_WRONG_ARGS; + _alpm_set_errno(handle, ALPM_ERR_WRONG_ARGS); return -1; } @@ -887,4 +892,17 @@ int SYMEXPORT alpm_option_set_disable_dl_timeout(alpm_handle_t *handle, return 0; } +void _alpm_set_errno(alpm_handle_t *handle, alpm_errno_t err) { +#ifdef HAVE_PTHREAD + alpm_errno_t *err_key = pthread_getspecific(handle->tkey_err); + if(!err_key) { + err_key = malloc(sizeof(alpm_errno_t)); + pthread_setspecific(handle->tkey_err, err_key); + } + *err_key = err; +#else + handle->pm_errno = err; +#endif +} + /* vim: set noet: */ -- cgit v1.2.3-24-g4f1b