uwrap: Introduce UWRAP_LOCK_ALL and UWRAP_UNLOCK_ALL macros
authorRobin Hack <hack.robin@gmail.com>
Fri, 23 Jan 2015 14:29:35 +0000 (15:29 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 28 Jan 2015 16:17:08 +0000 (17:17 +0100)
Introduce UWRAP_LOCK_ALL and UWRAP_UNLOCK_ALL which make
locking easier.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/uid_wrapper/uid_wrapper.c

index 50dfaa4b16559eedff9b17d237a8b81f2f0a20d6..b04e334cac51851c6c03de42913e9683673256aa 100644 (file)
        pthread_mutex_unlock(&( m ## _mutex)); \
 } while(0)
 
+/* Add new global locks here please */
+# define UWRAP_LOCK_ALL \
+       UWRAP_LOCK(uwrap_id); \
+       UWRAP_LOCK(libc_symbol_binding); \
+
+# define UWRAP_UNLOCK_ALL \
+       UWRAP_UNLOCK(libc_symbol_binding); \
+       UWRAP_UNLOCK(uwrap_id)
+
 #ifdef HAVE_CONSTRUCTOR_ATTRIBUTE
 #define CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor))
 #else
@@ -654,8 +663,8 @@ static int uwrap_new_id(pthread_t tid, bool do_alloc)
 
 static void uwrap_thread_prepare(void)
 {
-       UWRAP_LOCK(uwrap_id);
-       UWRAP_LOCK(libc_symbol_binding);
+       UWRAP_LOCK_ALL;
+
        /*
         * What happens if another atfork prepare functions calls a uwrap
         * function? So disable it in case another atfork prepare function
@@ -668,8 +677,7 @@ static void uwrap_thread_parent(void)
 {
        uwrap.enabled = true;
 
-       UWRAP_UNLOCK(libc_symbol_binding);
-       UWRAP_UNLOCK(uwrap_id);
+       UWRAP_UNLOCK_ALL;
 }
 
 static void uwrap_thread_child(void)
@@ -1624,8 +1632,7 @@ void uwrap_destructor(void)
 {
        struct uwrap_thread *u = uwrap.ids;
 
-       UWRAP_LOCK(uwrap_id);
-       UWRAP_LOCK(libc_symbol_binding);
+       UWRAP_LOCK_ALL;
 
        while (u != NULL) {
                UWRAP_DLIST_REMOVE(uwrap.ids, u);
@@ -1642,6 +1649,5 @@ void uwrap_destructor(void)
                dlclose(uwrap.libc.handle);
        }
 
-       UWRAP_UNLOCK(libc_symbol_binding);
-       UWRAP_UNLOCK(uwrap_id);
+       UWRAP_UNLOCK_ALL;
 }