summaryrefslogtreecommitdiff
path: root/lib/util/smb_threads.h
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@dworkin.(none)>2009-05-10 21:55:23 -0400
committerDerrell Lipman <derrell@dworkin.(none)>2009-05-10 22:45:12 -0400
commitd3434477e6d42432a0acf426fcfbe39eb11b1fd0 (patch)
tree9108912416b0d73081a5af2204c0c74422162ba2 /lib/util/smb_threads.h
parent831b73ec82717c3c73ea1250f9c94228d251c1ec (diff)
downloadsamba-d3434477e6d42432a0acf426fcfbe39eb11b1fd0.tar.gz
samba-d3434477e6d42432a0acf426fcfbe39eb11b1fd0.tar.bz2
samba-d3434477e6d42432a0acf426fcfbe39eb11b1fd0.zip
Replace external thread "once" with an internal implementation
Jeremy, please check... - I'm in the process of providing an interface in libsmbclient to the recently-added threading capabilities. In the process, I discovered that different thread implementations have varying types for the variable passed to the thread_impl_once() function. pthreads, for example, uses type pthread_once_t. Since Samba needs to internally declare these variables, it would need to know the exact type required by each thread implementation's function. After considering multiple methods of obtaining an appropriately sized variable, I decided that for the basic "once" functionality required by Samba, it would be much simpler to just implement our own "once" functionality. We don't require cancellation points et all. This commit adds an smb_thread_once() function that is implemented using an internal mutex. The mutex itself uses the implementation's create_mutex function. This eliminates the need for the user to provide a smb_thread_once function pointer and the entire issue of that function's first parameter. Derrell
Diffstat (limited to 'lib/util/smb_threads.h')
-rw-r--r--lib/util/smb_threads.h22
1 files changed, 2 insertions, 20 deletions
diff --git a/lib/util/smb_threads.h b/lib/util/smb_threads.h
index 4443c3eae4..f1a39a6e28 100644
--- a/lib/util/smb_threads.h
+++ b/lib/util/smb_threads.h
@@ -20,20 +20,10 @@
#ifndef _smb_threads_h_
#define _smb_threads_h_
-/* Data types needed for smb_thread_once call. */
-
-#if defined(HAVE_PTHREAD_H)
-#include <pthread.h>
-#define smb_thread_once_t pthread_once_t
-#define SMB_THREAD_ONCE_INIT PTHREAD_ONCE_INIT
-#define SMB_THREAD_ONCE_IS_INITIALIZED(val) (true)
-#define SMB_THREAD_ONCE_INITIALIZE(val)
-#else
-#define smb_thread_once_t bool
+typedef bool smb_thread_once_t;
#define SMB_THREAD_ONCE_INIT false
#define SMB_THREAD_ONCE_IS_INITIALIZED(val) ((val) == true)
#define SMB_THREAD_ONCE_INITIALIZE(val) ((val) = true)
-#endif
enum smb_thread_lock_type {
SMB_THREAD_LOCK = 1,
@@ -50,9 +40,6 @@ struct smb_thread_functions {
int (*lock_mutex)(void *plock, enum smb_thread_lock_type lock_type,
const char *location);
- /* Once initialization. */
- int (*smb_thread_once)(smb_thread_once_t *p_once, void (*init_fn)(void));
-
/* Thread local storage. */
int (*create_tls)(const char *keyname,
void **ppkey,
@@ -64,6 +51,7 @@ struct smb_thread_functions {
};
int smb_thread_set_functions(const struct smb_thread_functions *tf);
+void smb_thread_once(smb_thread_once_t *ponce, void (*init_fn)(void));
extern const struct smb_thread_functions *global_tfp;
@@ -97,11 +85,6 @@ static int smb_lock_pthread(void *plock, enum smb_thread_lock_type lock_type, co
} \
} \
\
-static int smb_thread_once_pthread(smb_thread_once_t *p_once, void (*init_fn)(void)) \
-{ \
- return pthread_once(p_once, init_fn); \
-} \
- \
static int smb_create_tls_pthread(const char *keyname, void **ppkey, const char *location) \
{ \
int ret; \
@@ -142,7 +125,6 @@ static const struct smb_thread_functions (tf) = { \
smb_create_mutex_pthread, \
smb_destroy_mutex_pthread, \
smb_lock_pthread, \
- smb_thread_once_pthread, \
smb_create_tls_pthread, \
smb_destroy_tls_pthread, \
smb_set_tls_pthread, \