diff options
Diffstat (limited to 'lib/util/smb_threads.c')
-rw-r--r-- | lib/util/smb_threads.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/util/smb_threads.c b/lib/util/smb_threads.c index 84dec4d874..fa2d8da186 100644 --- a/lib/util/smb_threads.c +++ b/lib/util/smb_threads.c @@ -25,8 +25,6 @@ #include "includes.h" -#define NUM_GLOBAL_LOCKS 1 - /********************************************************* Functions to vector the locking primitives used internally by libsmbclient. @@ -50,8 +48,19 @@ int smb_thread_set_functions(const struct smb_thread_functions *tf) global_tfp = tf; +#if defined(PARANOID_MALLOC_CHECKER) +#ifdef malloc +#undef malloc +#endif +#endif + /* Here we initialize any static locks we're using. */ - global_lock_array = (void **)SMB_MALLOC_ARRAY(void *, NUM_GLOBAL_LOCKS); + global_lock_array = (void **)malloc(sizeof(void *) *NUM_GLOBAL_LOCKS); + +#if defined(PARANOID_MALLOC_CHECKER) +#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY +#endif + if (global_lock_array == NULL) { return ENOMEM; } @@ -62,9 +71,11 @@ int smb_thread_set_functions(const struct smb_thread_functions *tf) SAFE_FREE(global_lock_array); return ENOMEM; } - global_tfp->create_mutex(name, + if (global_tfp->create_mutex(name, &global_lock_array[i], - __location__); + __location__)) { + smb_panic("smb_thread_set_functions: create mutexes failed"); + } SAFE_FREE(name); } @@ -81,14 +92,18 @@ int smb_thread_set_functions(const struct smb_thread_functions *tf) SMB_THREADS_DEF_PTHREAD_IMPLEMENTATION(tf); +void *pkey = NULL; + /* Test function. */ int test_threads(void) { int ret; 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); + } if ((ret = SMB_THREAD_CREATE_MUTEX("test", plock)) != 0) { printf("Create lock error: %d\n", ret); } @@ -99,6 +114,7 @@ int test_threads(void) printf("unlock error: %d\n", ret); } SMB_THREAD_DESTROY_MUTEX(plock); + SMB_THREAD_DESTROY_TLS_ONCE(pkey); return 0; } |