summaryrefslogtreecommitdiff
path: root/lib/util/smb_threads.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-04-20 03:04:42 -0700
committerJeremy Allison <jra@samba.org>2009-04-20 03:04:42 -0700
commit3d2e95c296a1858986b9c806dff67c9cc3d8f70d (patch)
tree70d1b5f20c483061f80c515fd23832fb9e0fdf24 /lib/util/smb_threads.c
parent03abc846ee14a08e585c0997a6235ea01db8352f (diff)
downloadsamba-3d2e95c296a1858986b9c806dff67c9cc3d8f70d.tar.gz
samba-3d2e95c296a1858986b9c806dff67c9cc3d8f70d.tar.bz2
samba-3d2e95c296a1858986b9c806dff67c9cc3d8f70d.zip
Fix the pthread_once initialization issue. Make talloc_stackframe use
this. Jeremy.
Diffstat (limited to 'lib/util/smb_threads.c')
-rw-r--r--lib/util/smb_threads.c25
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;
}