diff options
author | Jeremy Allison <jra@samba.org> | 2009-04-20 03:04:42 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-04-20 03:04:42 -0700 |
commit | 3d2e95c296a1858986b9c806dff67c9cc3d8f70d (patch) | |
tree | 70d1b5f20c483061f80c515fd23832fb9e0fdf24 /lib/util/talloc_stack.c | |
parent | 03abc846ee14a08e585c0997a6235ea01db8352f (diff) | |
download | samba-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/talloc_stack.c')
-rw-r--r-- | lib/util/talloc_stack.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c index f572dd6c77..f5ca9d21d5 100644 --- a/lib/util/talloc_stack.c +++ b/lib/util/talloc_stack.c @@ -55,7 +55,25 @@ struct talloc_stackframe { static void *global_ts; -static struct talloc_stackframe *talloc_stackframe_init(void) +/* Variable to ensure TLS value is only initialized once. */ +static smb_thread_once_t ts_initialized = SMB_THREAD_ONCE_INIT; + +static void talloc_stackframe_init(void) +{ + if (!global_tfp) { + /* Non-thread safe init case. */ + if (ts_initialized) { + return; + } + ts_initialized = true; + } + + if (SMB_THREAD_CREATE_TLS("talloc_stackframe", global_ts)) { + smb_panic("talloc_stackframe_init create_tls failed"); + } +} + +static struct talloc_stackframe *talloc_stackframe_create(void) { #if defined(PARANOID_MALLOC_CHECKER) #ifdef malloc @@ -74,9 +92,7 @@ static struct talloc_stackframe *talloc_stackframe_init(void) ZERO_STRUCTP(ts); - if (SMB_THREAD_CREATE_TLS_ONCE("talloc_stackframe", global_ts)) { - smb_panic("talloc_stackframe_init create_tls failed"); - } + SMB_THREAD_ONCE(&ts_initialized, talloc_stackframe_init); if (SMB_THREAD_SET_TLS(global_ts, ts)) { smb_panic("talloc_stackframe_init set_tls failed"); @@ -115,7 +131,7 @@ static TALLOC_CTX *talloc_stackframe_internal(size_t poolsize) (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); if (ts == NULL) { - ts = talloc_stackframe_init(); + ts = talloc_stackframe_create(); } if (ts->talloc_stack_arraysize < ts->talloc_stacksize + 1) { |