summaryrefslogtreecommitdiff
path: root/lib/util/smb_threads.c
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@dworkin.(none)>2009-05-13 09:49:59 -0400
committerDerrell Lipman <derrell@dworkin.(none)>2009-05-13 09:50:17 -0400
commite03b9ae609a3ef856c483832332e307975a1bf0a (patch)
treed60aec946ceedc3bfe5205853a769b15a59953b1 /lib/util/smb_threads.c
parent652251701df7dec1401eab9b1dbc7e3ac5c7e7ad (diff)
downloadsamba-e03b9ae609a3ef856c483832332e307975a1bf0a.tar.gz
samba-e03b9ae609a3ef856c483832332e307975a1bf0a.tar.bz2
samba-e03b9ae609a3ef856c483832332e307975a1bf0a.zip
Allow a parameter to smb_thread_once's initialization function
- This should make life easier for ourselves. We're no longer constrained to the semantics of pthread_once, so let's allow passing a parameter to the initialization function. Some of Samba's init functions return a value. Although I haven't searched, I suspect that some of the init functions require in input parameters. The parameter added here can be used for input, output, or both, as necessary... or ignored, as is now done in talloc_stackframe_init(). Derrell
Diffstat (limited to 'lib/util/smb_threads.c')
-rw-r--r--lib/util/smb_threads.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/util/smb_threads.c b/lib/util/smb_threads.c
index e2d01f775a..ffe2eb0114 100644
--- a/lib/util/smb_threads.c
+++ b/lib/util/smb_threads.c
@@ -105,33 +105,44 @@ int smb_thread_set_functions(const struct smb_thread_functions *tf)
implementation's "once" type.
********************************************************************/
-int smb_thread_once(smb_thread_once_t *ponce, void (*init_fn)(void))
+int smb_thread_once(smb_thread_once_t *ponce,
+ void (*init_fn)(void *pdata),
+ void *pdata)
{
int ret;
/* Lock our "once" mutex in order to test and initialize ponce */
- if ((ret = SMB_THREAD_LOCK(once_mutex, SMB_THREAD_LOCK)) != 0) {
+ if (SMB_THREAD_LOCK(once_mutex, SMB_THREAD_LOCK) != 0) {
smb_panic("error locking 'once'");
}
+ /* Keep track of whether we ran their init function */
+ ret = ! *ponce;
+
/*
* See if another thread got here after we tested it initially but
* before we got our lock.
*/
if (! *ponce) {
/* Nope, we need to run the initialization function */
- (*init_fn)();
+ (*init_fn)(pdata);
/* Now we can indicate that the function has been run */
*ponce = true;
}
/* Unlock the mutex */
- if ((ret = SMB_THREAD_LOCK(once_mutex, SMB_THREAD_UNLOCK)) != 0) {
+ if (SMB_THREAD_LOCK(once_mutex, SMB_THREAD_UNLOCK) != 0) {
smb_panic("error unlocking 'once'");
}
-
- return 0;
+
+ /*
+ * Tell 'em whether we ran their init function. If they passed a data
+ * pointer to the init function and the init function could change
+ * something in the pointed-to data, this will tell them whether that
+ * data is valid or not.
+ */
+ return ret;
}