diff options
author | bje <bje> | 1998-07-19 22:26:42 +0000 |
---|---|---|
committer | bje <bje> | 1998-07-19 22:26:42 +0000 |
commit | f79b5dbeba8340efaa801cb26be12c2c5a1fab05 (patch) | |
tree | 725d55da284108f75b71e7d49e9c6fc33aaa0e6d | |
parent | 5e84109c56a3a11dcdf0a42b77c9a910012f7061 (diff) |
1998-07-20 Ben Elliston <bje@cygnus.com>
* misc.c (pthread_once): Implement.
-rw-r--r-- | misc.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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) { |