summaryrefslogtreecommitdiff
path: root/src/posix-lock.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2017-11-29 20:22:06 +0100
committerWerner Koch <wk@gnupg.org>2017-11-29 20:22:06 +0100
commitadc786d034b63176b941a1ef8d996acbf8d0ea5d (patch)
treeb19d82491cc7666f18cb44d2f7458f2f28fbe936 /src/posix-lock.c
parent1865c0ba1769b407a3c504f1ab0a4278704a9fc1 (diff)
downloadlibgpg-error-adc786d034b63176b941a1ef8d996acbf8d0ea5d.tar.gz
core: Unify syscall_clamp functions.
* src/estream.c (_gpgrt_set_syscall_clamp) (_gpgrt_get_syscall_clamp): Move to ... * src/syscall-clamp.c: new file. (_gpgrt_pre_syscall, _gpgrt_post_syscall): New. * src/Makefile.am (libgpg_error_la_SOURCES): Add that file. * src/estream.c: Replace the syscall wrapper with the new functions. * src/posix-lock.c: Ditto. * src/w32-lock.c: Ditto. * src/posix-thread.c: Ditto. * src/w32-thread.c: Ditto. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/posix-lock.c')
-rw-r--r--src/posix-lock.c37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/posix-lock.c b/src/posix-lock.c
index d251d2f..b5e6916 100644
--- a/src/posix-lock.c
+++ b/src/posix-lock.c
@@ -39,19 +39,11 @@
# include <pthread.h>
#endif
-#include "gpg-error.h"
+#include "gpgrt-int.h"
#include "lock.h"
#include "posix-lock-obj.h"
-/*
- * Functions called before and after blocking syscalls.
- * gpgrt_set_syscall_clamp is used to set them.
- */
-static void (*pre_lock_func)(void);
-static void (*post_lock_func)(void);
-
-
#if USE_POSIX_THREADS
# if USE_POSIX_THREADS_WEAK
/* On ELF systems it is easy to use pthreads using weak
@@ -111,17 +103,6 @@ use_pthread_p (void)
#endif /*USE_POSIX_THREADS*/
-/* Helper to set the clamp functions. This is called as a helper from
- * _gpgrt_set_syscall_clamp to keep the function pointers local. */
-void
-_gpgrt_lock_set_lock_clamp (void (*pre)(void), void (*post)(void))
-{
- pre_lock_func = pre;
- post_lock_func = post;
-}
-
-
-
static _gpgrt_lock_t *
get_lock_object (gpgrt_lock_t *lockhd)
{
@@ -168,7 +149,7 @@ _gpgrt_lock_init (gpgrt_lock_t *lockhd)
{
rc = pthread_mutex_init (&lock->u.mtx, NULL);
if (rc)
- rc = gpg_err_code_from_errno (rc);
+ rc = _gpg_err_code_from_errno (rc);
}
else
rc = 0; /* Threads are not used. */
@@ -189,13 +170,11 @@ _gpgrt_lock_lock (gpgrt_lock_t *lockhd)
#if USE_POSIX_THREADS
if (use_pthread_p())
{
- if (pre_lock_func)
- pre_lock_func ();
+ _gpgrt_pre_syscall ();
rc = pthread_mutex_lock (&lock->u.mtx);
if (rc)
- rc = gpg_err_code_from_errno (rc);
- if (post_lock_func)
- post_lock_func ();
+ rc = _gpg_err_code_from_errno (rc);
+ _gpgrt_post_syscall ();
}
else
rc = 0; /* Threads are not used. */
@@ -218,7 +197,7 @@ _gpgrt_lock_trylock (gpgrt_lock_t *lockhd)
{
rc = pthread_mutex_trylock (&lock->u.mtx);
if (rc)
- rc = gpg_err_code_from_errno (rc);
+ rc = _gpg_err_code_from_errno (rc);
}
else
rc = 0; /* Threads are not used. */
@@ -241,7 +220,7 @@ _gpgrt_lock_unlock (gpgrt_lock_t *lockhd)
{
rc = pthread_mutex_unlock (&lock->u.mtx);
if (rc)
- rc = gpg_err_code_from_errno (rc);
+ rc = _gpg_err_code_from_errno (rc);
}
else
rc = 0; /* Threads are not used. */
@@ -266,7 +245,7 @@ _gpgrt_lock_destroy (gpgrt_lock_t *lockhd)
{
rc = pthread_mutex_destroy (&lock->u.mtx);
if (rc)
- rc = gpg_err_code_from_errno (rc);
+ rc = _gpg_err_code_from_errno (rc);
else
{
/* Re-init the mutex so that it can be re-used. */