From: Stefan Metzmacher Date: Mon, 12 May 2025 18:43:08 +0000 (+0200) Subject: lib/util: remove unused SMB_THREAD handling from talloc_stack.c X-Git-Tag: tevent-0.17.0~161 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3a5f9748cf3d6115a1c65647875b506c4c551fb;p=thirdparty%2Fsamba.git lib/util: remove unused SMB_THREAD handling from talloc_stack.c This does not support any threads as smb_thread_set_functions() is never called anywhere. We'll add plain pthread handling in the next commit. Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c index fdd0a30441d..d541ed01603 100644 --- a/lib/util/talloc_stack.c +++ b/lib/util/talloc_stack.c @@ -40,8 +40,6 @@ #include "replace.h" #include #include "lib/util/talloc_stack.h" -#include "lib/util/smb_threads.h" -#include "lib/util/smb_threads_internal.h" #include "lib/util/fault.h" #include "lib/util/debug.h" @@ -51,55 +49,47 @@ struct talloc_stackframe { TALLOC_CTX **talloc_stack; }; -/* - * In the single threaded case this is a pointer - * to the global talloc_stackframe. In the MT-case - * this is the pointer to the thread-specific key - * used to look up the per-thread talloc_stackframe - * pointer. - */ +static struct talloc_stackframe *global_ts; -static void *global_ts; +static struct talloc_stackframe *talloc_stackframe_get_existing(void) +{ + struct talloc_stackframe *ts = NULL; -/* Variable to ensure TLS value is only initialized once. */ -static smb_thread_once_t ts_initialized = SMB_THREAD_ONCE_INIT; + ts = global_ts; -static void talloc_stackframe_init(void * unused) -{ - if (SMB_THREAD_CREATE_TLS("talloc_stackframe", global_ts)) { - smb_panic("talloc_stackframe_init create_tls failed"); - } + return ts; } -static struct talloc_stackframe *talloc_stackframe_create(void) +static struct talloc_stackframe *talloc_stackframe_get(void) { + struct talloc_stackframe *ts = talloc_stackframe_get_existing(); + + if (ts != NULL) { + return ts; + } + #if defined(PARANOID_MALLOC_CHECKER) #ifdef calloc #undef calloc #endif #endif - struct talloc_stackframe *ts = (struct talloc_stackframe *)calloc( + ts = (struct talloc_stackframe *)calloc( 1, sizeof(struct talloc_stackframe)); #if defined(PARANOID_MALLOC_CHECKER) #define calloc(n, s) __ERROR_DONT_USE_MALLOC_DIRECTLY #endif - if (!ts) { smb_panic("talloc_stackframe_init malloc failed"); } - SMB_THREAD_ONCE(&ts_initialized, talloc_stackframe_init, NULL); + global_ts = ts; - if (SMB_THREAD_SET_TLS(global_ts, ts)) { - smb_panic("talloc_stackframe_init set_tls failed"); - } return ts; } static int talloc_pop(TALLOC_CTX *frame) { - struct talloc_stackframe *ts = - (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); + struct talloc_stackframe *ts = talloc_stackframe_get_existing(); size_t blocks; int i; @@ -165,12 +155,7 @@ static TALLOC_CTX *talloc_stackframe_internal(const char *location, size_t poolsize) { TALLOC_CTX **tmp, *top; - struct talloc_stackframe *ts = - (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); - - if (ts == NULL) { - ts = talloc_stackframe_create(); - } + struct talloc_stackframe *ts = talloc_stackframe_get(); if (ts->talloc_stack_arraysize < ts->talloc_stacksize + 1) { tmp = talloc_realloc(NULL, ts->talloc_stack, TALLOC_CTX *, @@ -225,17 +210,16 @@ TALLOC_CTX *_talloc_stackframe_pool(const char *location, size_t poolsize) TALLOC_CTX *_talloc_tos(const char *location) { - struct talloc_stackframe *ts = - (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); + struct talloc_stackframe *ts = talloc_stackframe_get_existing(); if (ts == NULL || ts->talloc_stacksize == 0) { - _talloc_stackframe(location); - ts = (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); + TALLOC_CTX *ret = _talloc_stackframe(location); DEBUG(0, ("no talloc stackframe at %s, leaking memory\n", location)); #ifdef DEVELOPER smb_panic("No talloc stackframe"); #endif + return ret; } return ts->talloc_stack[ts->talloc_stacksize-1]; @@ -249,8 +233,7 @@ TALLOC_CTX *_talloc_tos(const char *location) bool talloc_stackframe_exists(void) { - struct talloc_stackframe *ts = - (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); + struct talloc_stackframe *ts = talloc_stackframe_get_existing(); if (ts == NULL || ts->talloc_stacksize == 0) { return false;