diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-04-20 16:53:02 +0200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-04-20 16:53:02 +0200 |
commit | 6c9caed48187a0d18becf59ab636af44cbe521b0 (patch) | |
tree | c47170169077be6f8ae60aed739803ab4ba861b7 /lib/util/smb_threads.c | |
parent | 53765c81f726a8c056cc4e57004592dd489975c9 (diff) | |
parent | 31120c9eacafd93e0f2c6b0f906af21adadd318a (diff) | |
download | samba-6c9caed48187a0d18becf59ab636af44cbe521b0.tar.gz samba-6c9caed48187a0d18becf59ab636af44cbe521b0.tar.bz2 samba-6c9caed48187a0d18becf59ab636af44cbe521b0.zip |
Merge commit 'origin/master' into libcli-auth-merge-without-netlogond
Diffstat (limited to 'lib/util/smb_threads.c')
-rw-r--r-- | lib/util/smb_threads.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/util/smb_threads.c b/lib/util/smb_threads.c index fa2d8da186..783e660b7f 100644 --- a/lib/util/smb_threads.c +++ b/lib/util/smb_threads.c @@ -92,8 +92,26 @@ int smb_thread_set_functions(const struct smb_thread_functions *tf) SMB_THREADS_DEF_PTHREAD_IMPLEMENTATION(tf); +static smb_thread_once_t ot = SMB_THREAD_ONCE_INIT; void *pkey = NULL; +static void init_fn(void) +{ + int ret; + + if (!global_tfp) { + /* Non-thread safe init case. */ + if (ot) { + return; + } + ot = true; + } + + if ((ret = SMB_THREAD_CREATE_TLS("test_tls", pkey)) != 0) { + printf("Create tls once error: %d\n", ret); + } +} + /* Test function. */ int test_threads(void) { @@ -101,9 +119,8 @@ int test_threads(void) void *plock = NULL; smb_thread_set_functions(&tf); - if ((ret = SMB_THREAD_CREATE_TLS_ONCE("test_tls", pkey)) != 0) { - printf("Create tls once error: %d\n", ret); - } + SMB_THREAD_ONCE(&ot, init_fn); + if ((ret = SMB_THREAD_CREATE_MUTEX("test", plock)) != 0) { printf("Create lock error: %d\n", ret); } @@ -114,7 +131,7 @@ int test_threads(void) printf("unlock error: %d\n", ret); } SMB_THREAD_DESTROY_MUTEX(plock); - SMB_THREAD_DESTROY_TLS_ONCE(pkey); + SMB_THREAD_DESTROY_TLS(pkey); return 0; } |