diff options
author | Werner Koch <[email protected]> | 2016-11-11 19:26:49 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-11-11 19:28:09 +0000 |
commit | 25d463c67821901c8fd6736c815f11e85bbae66f (patch) | |
tree | 7034ee2e99db85225425fe2410654fd53f51dfb3 /src/posix-lock.c | |
parent | w32: Fix lock c++ narrowing conversion warning (diff) | |
download | libgpg-error-25d463c67821901c8fd6736c815f11e85bbae66f.tar.gz libgpg-error-25d463c67821901c8fd6736c815f11e85bbae66f.zip |
Use the syscall clamp functions also for lock functions
* src/posix-lock.c (pre_lock_func, post_lock_func): New.
(_gpgrt_lock_set_lock_clamp): New.
(_gpgrt_lock_lock): Use clamp functions.
* src/w32-lock.c (pre_lock_func, post_lock_func): New.
(_gpgrt_lock_set_lock_clamp): New.
(_gpgrt_lock_lock): Use clamp functions.
* src/posix-lock.c (pre_syscall_func, post_syscall_func): New.
(_gpgrt_thread_set_syscall_clamp): New.
(_gpgrt_yield): Use clamp functions.
* src/w32-lock.c (pre_syscall_func, post_syscall_func): New.
(_gpgrt_thread_set_syscall_clamp): New.
(_gpgrt_yield): Use clamp functions.
* src/estream.c: Include lock.h and thread.h.
(do_deinit): Call _gpgrt_lock_set_lock_clamp.
(_gpgrt_set_syscall_clamp): Ditto.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/posix-lock.c')
-rw-r--r-- | src/posix-lock.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/posix-lock.c b/src/posix-lock.c index 2e0ae92..d251d2f 100644 --- a/src/posix-lock.c +++ b/src/posix-lock.c @@ -44,6 +44,14 @@ #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 @@ -103,6 +111,16 @@ 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) @@ -171,9 +189,13 @@ _gpgrt_lock_lock (gpgrt_lock_t *lockhd) #if USE_POSIX_THREADS if (use_pthread_p()) { + if (pre_lock_func) + pre_lock_func (); rc = pthread_mutex_lock (&lock->u.mtx); if (rc) rc = gpg_err_code_from_errno (rc); + if (post_lock_func) + post_lock_func (); } else rc = 0; /* Threads are not used. */ |