Make the thread functions a bit easier to use
authorDerrell Lipman <derrell@dworkin.(none)>
Wed, 13 May 2009 18:31:40 +0000 (14:31 -0400)
committerDerrell Lipman <derrell@dworkin.(none)>
Wed, 13 May 2009 18:37:28 +0000 (14:37 -0400)
- Create separate macros for lock and unlock so that it's easier to identify
  which request is being made.

- Initialize *ponce in the SMB_THREAD_ONCE macro in the non-thread-safe case,
  rather than requiring each init function to determine if it's in the
  non-thread-safe case and manually initialize.

Derrell

lib/util/smb_threads.c
lib/util/smb_threads.h
lib/util/smb_threads_internal.h

index ffe2eb011423c3977a9bef373b6addd691a2c085..58ea2daa67563bc831dffd811ec23e75f1a18f0f 100644 (file)
@@ -43,7 +43,7 @@ void **global_lock_array;
  Mutex used for our internal "once" function
 *********************************************************/
 
-void *once_mutex = NULL;
+static void *once_mutex = NULL;
 
 
 /*********************************************************
@@ -112,7 +112,7 @@ int smb_thread_once(smb_thread_once_t *ponce,
         int ret;
 
         /* Lock our "once" mutex in order to test and initialize ponce */
-       if (SMB_THREAD_LOCK(once_mutex, SMB_THREAD_LOCK) != 0) {
+       if (SMB_THREAD_LOCK(once_mutex) != 0) {
                 smb_panic("error locking 'once'");
        }
 
@@ -132,7 +132,7 @@ int smb_thread_once(smb_thread_once_t *ponce,
         }
 
         /* Unlock the mutex */
-       if (SMB_THREAD_LOCK(once_mutex, SMB_THREAD_UNLOCK) != 0) {
+       if (SMB_THREAD_UNLOCK(once_mutex) != 0) {
                 smb_panic("error unlocking 'once'");
        }
         
index 809673ab544b245afe6c653061862525decab4a7..9a096167743383c76b9d00d19a3766f826421d91 100644 (file)
@@ -22,8 +22,6 @@
 
 typedef bool smb_thread_once_t;
 #define SMB_THREAD_ONCE_INIT false
-#define SMB_THREAD_ONCE_IS_INITIALIZED(val) ((val) == true)
-#define SMB_THREAD_ONCE_INITIALIZE(val) ((val) = true)
 
 enum smb_thread_lock_type {
        SMB_THREAD_LOCK = 1,
index 038c584b608c151c8d78ee40a038445edcf838b2..afd7559f3b001a536eb8ca977375f20c59f1e130 100644 (file)
                }; \
        } while (0)
 
-#define SMB_THREAD_LOCK(plock, type) \
-       (global_tfp ? global_tfp->lock_mutex((plock), (type), __location__) : 0)
+#define SMB_THREAD_LOCK_INTERNAL(plock, type, location) \
+       (global_tfp ? global_tfp->lock_mutex((plock), (type), location) : 0)
+
+#define SMB_THREAD_LOCK(plock) \
+        SMB_THREAD_LOCK_INTERNAL(plock, SMB_THREAD_LOCK, __location__)
+
+#define SMB_THREAD_UNLOCK(plock) \
+        SMB_THREAD_LOCK_INTERNAL(plock, SMB_THREAD_UNLOCK, __location__)
 
 #define SMB_THREAD_ONCE(ponce, init_fn, pdata)                  \
         (global_tfp                                             \
          ? (! *(ponce)                                          \
             ? smb_thread_once((ponce), (init_fn), (pdata))      \
             : 0)                                                \
-         : ((init_fn(pdata)), 0))
+         : ((init_fn(pdata)), *(ponce) = true, 1))
 
 #define SMB_THREAD_CREATE_TLS(keyname, key) \
        (global_tfp ? global_tfp->create_tls((keyname), &(key), __location__) : 0)