Optimize smb_thread_once usage by not calling it if known already called
authorDerrell Lipman <derrell@dworkin.(none)>
Mon, 11 May 2009 02:58:12 +0000 (22:58 -0400)
committerDerrell Lipman <derrell@dworkin.(none)>
Mon, 11 May 2009 02:58:12 +0000 (22:58 -0400)
- The macro SMB_THREAD_ONCE now tests whether the "once" variable is already
  set, and if so avoids calling smb_thread_once().

Derrell

lib/util/smb_threads_internal.h

index 0260934e158b6e1e76b985febb56b29628053f04..29a581b01394ecf4496e844068d1e411b94b830d 100644 (file)
 #define SMB_THREAD_LOCK(plock, type) \
        (global_tfp ? global_tfp->lock_mutex((plock), (type), __location__) : 0)
 
-#define SMB_THREAD_ONCE(ponce, init_fn) \
-       (global_tfp ? smb_thread_once((ponce), (init_fn)) : ((init_fn()), 0))
+#define SMB_THREAD_ONCE(ponce, init_fn)                 \
+        (global_tfp                                     \
+         ? (! *(ponce)                                  \
+            ? smb_thread_once((ponce), (init_fn))       \
+            : 0)                                        \
+         : ((init_fn()), 0))
 
 #define SMB_THREAD_CREATE_TLS(keyname, key) \
        (global_tfp ? global_tfp->create_tls((keyname), &(key), __location__) : 0)