rbb 01/08/26 20:17:16
Modified: . CHANGES
include apr_thread_proc.h
include/arch/unix threadproc.h
threadproc/unix thread.c
Log:
Add an apr_thread_once function to allow a program to make sure that
a function is only called once.
Revision Changes Path
1.146 +5 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- CHANGES 2001/08/24 18:04:24 1.145
+++ CHANGES 2001/08/27 03:17:15 1.146
@@ -1,4 +1,9 @@
Changes with APR b1
+
+ *) Add an apr_thread_once function to APR. This allows a
+ program to ensure that a function is only called once.
+ [Ryan Bloom]
+
*) APR Documentation is now in Doxygen format.
[Ian Holsman]
1.73 +22 -0 apr/include/apr_thread_proc.h
Index: apr_thread_proc.h
===================================================================
RCS file: /home/cvs/apr/include/apr_thread_proc.h,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- apr_thread_proc.h 2001/08/24 17:15:01 1.72
+++ apr_thread_proc.h 2001/08/27 03:17:15 1.73
@@ -129,6 +129,7 @@
typedef struct apr_thread_t apr_thread_t;
typedef struct apr_threadattr_t apr_threadattr_t;
typedef struct apr_procattr_t apr_procattr_t;
+typedef struct apr_thread_once_t apr_thread_once_t;
typedef struct apr_threadkey_t apr_threadkey_t;
#if APR_HAS_OTHER_CHILD
@@ -223,6 +224,27 @@
* force the current thread to yield the processor
*/
APR_DECLARE(void) apr_thread_yield(void);
+
+/**
+ * Initialize the control variable for apr_thread_once. If this isn't
+ * called, apr_initialize won't work.
+ * @param control The control variable to initialize
+ * @param p The pool to allocate data from.
+ */
+APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
+ apr_pool_t *p);
+
+/**
+ * Run the specified function one time, regardless of how many threads
+ * call it.
+ * @param control The control variable. The same variable should
+ * be passed in each time the function is tried to be
+ * called. This is how the underlying functions determine
+ * if the function has ever been called before.
+ * @param func The function to call.
+ */
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+ void (*func)(void));
/**
* detach a thread
1.20 +5 -0 apr/include/arch/unix/threadproc.h
Index: threadproc.h
===================================================================
RCS file: /home/cvs/apr/include/arch/unix/threadproc.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- threadproc.h 2001/07/24 05:16:32 1.19
+++ threadproc.h 2001/08/27 03:17:15 1.20
@@ -103,6 +103,11 @@
apr_pool_t *cntxt;
pthread_key_t key;
};
+
+struct apr_thread_once_t {
+ pthread_once_t once;
+};
+
#endif
struct apr_procattr_t {
1.46 +13 -0 apr/threadproc/unix/thread.c
Index: thread.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/thread.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- thread.c 2001/08/10 21:04:48 1.45
+++ thread.c 2001/08/27 03:17:15 1.46
@@ -255,6 +255,19 @@
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
+ apr_pool_t *p)
+{
+ (*control)->once = PTHREAD_ONCE_INIT;
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+ void (*func)(void))
+{
+ return pthread_once(&control->once, func);
+}
+
APR_POOL_IMPLEMENT_ACCESSOR_X(thread, cntxt)
#endif /* HAVE_PTHREAD_H */