summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbje <bje>1998-07-19 22:26:42 +0000
committerbje <bje>1998-07-19 22:26:42 +0000
commitf79b5dbeba8340efaa801cb26be12c2c5a1fab05 (patch)
tree725d55da284108f75b71e7d49e9c6fc33aaa0e6d
parent5e84109c56a3a11dcdf0a42b77c9a910012f7061 (diff)
1998-07-20 Ben Elliston <bje@cygnus.com>
* misc.c (pthread_once): Implement.
-rw-r--r--misc.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index eb5b5cf..f58005b 100644
--- a/misc.c
+++ b/misc.c
@@ -7,6 +7,40 @@
#include "pthread.h"
+int
+pthread_once(pthread_once_t *once_control,
+ void (*init_routine)(void))
+{
+ /* A flag, allocated per invocation, that indicates if the amotic
+ test-and-set occured. */
+ unsigned short flag = 0;
+
+ if (once_control == NULL || init_routine == NULL)
+ {
+ return EINVAL;
+ }
+
+ /* FIXME: we are assuming that the `cs' object is initialised at DLL
+ load time. Likewise, the object should be destroyed when (if)
+ the DLL is unloaded. */
+
+ /* An atomic test-and-set of the "once" flag. */
+ EnterCriticalSection(&_pthread_once_lock);
+ if (_pthread_once_flag == 0)
+ {
+ flag = _pthread_once_flag = 1;
+ }
+ LeaveCriticalSection(&_pthread_once_lock);
+
+ if (flag)
+ {
+ /* Run the init routine. */
+ init_routine();
+ }
+
+ return 0;
+}
+
pthread_t
pthread_self(void)
{