From ba1101b8755f1e843af4d9b160533f0b11e4b598 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 27 Jan 2018 20:17:48 +0100 Subject: Use libc lock instead of cthreads lock for atfork_lock * forward.c: Include (atfork_lock): Use libc_lock instead of struct mutex. (atfork_pthread_prepare, atfork_pthread_parent, atfork_pthread_child, __register_atfork, __unregister_atfork): Use __libc_lock_lock/unlock instead of __mutex_lock/unlock. --- forward.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'forward.c') diff --git a/forward.c b/forward.c index 0ee84a0..ea25935 100644 --- a/forward.c +++ b/forward.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /* Pointers to the libc functions. */ @@ -155,7 +156,7 @@ struct atfork { }; /* TODO: better locking */ -static struct mutex atfork_lock; +__libc_lock_define_initialized(static, atfork_lock); static struct atfork *fork_handlers, *fork_last_handler; static void @@ -163,10 +164,10 @@ atfork_pthread_prepare (void) { struct atfork *handlers, *last_handler; - __mutex_lock (&atfork_lock); + __libc_lock_lock (atfork_lock); handlers = fork_handlers; last_handler = fork_last_handler; - __mutex_unlock (&atfork_lock); + __libc_lock_unlock (atfork_lock); if (!last_handler) return; @@ -187,9 +188,9 @@ atfork_pthread_parent (void) { struct atfork *handlers; - __mutex_lock (&atfork_lock); + __libc_lock_lock (atfork_lock); handlers = fork_handlers; - __mutex_unlock (&atfork_lock); + __libc_lock_unlock (atfork_lock); while (handlers) { @@ -205,9 +206,9 @@ atfork_pthread_child (void) { struct atfork *handlers; - __mutex_lock (&atfork_lock); + __libc_lock_lock (atfork_lock); handlers = fork_handlers; - __mutex_unlock (&atfork_lock); + __libc_lock_unlock (atfork_lock); while (handlers) { @@ -235,14 +236,14 @@ __register_atfork ( new->dso_handle = dso_handle; new->prev = NULL; - __mutex_lock (&atfork_lock); + __libc_lock_lock (atfork_lock); new->next = fork_handlers; if (fork_handlers) fork_handlers->prev = new; fork_handlers = new; if (!fork_last_handler) fork_last_handler = new; - __mutex_unlock (&atfork_lock); + __libc_lock_unlock (atfork_lock); return 0; } @@ -252,7 +253,7 @@ void __unregister_atfork (void *dso_handle) { struct atfork **handlers, *prev = NULL, *next; - __mutex_lock (&atfork_lock); + __libc_lock_lock (atfork_lock); handlers = &fork_handlers; while (*handlers) { @@ -277,5 +278,5 @@ __unregister_atfork (void *dso_handle) handlers = &prev->next; } } - __mutex_unlock (&atfork_lock); + __libc_lock_unlock (atfork_lock); } -- cgit v1.2.3