diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-08-16 19:49:29 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-08-16 19:49:29 +0000 |
commit | 977ea13751d8f39c9e72539d60c769467c49c29e (patch) | |
tree | 2a6696261276d1b5ba75b59a2c3c638a6464c26f | |
parent | ca9af6c7397b9dcb95ae80ad6a7a43a8b3444f1c (diff) | |
download | glibc-977ea13751d8f39c9e72539d60c769467c49c29e.tar glibc-977ea13751d8f39c9e72539d60c769467c49c29e.tar.gz glibc-977ea13751d8f39c9e72539d60c769467c49c29e.tar.bz2 glibc-977ea13751d8f39c9e72539d60c769467c49c29e.zip |
Introduce thread-specific key handling functions.
-rw-r--r-- | sysdeps/mach/libc-lock.h | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/sysdeps/mach/libc-lock.h b/sysdeps/mach/libc-lock.h index 0b80b1ca51..b2acda53cd 100644 --- a/sysdeps/mach/libc-lock.h +++ b/sysdeps/mach/libc-lock.h @@ -27,6 +27,9 @@ typedef struct __libc_lock_opaque__ __libc_lock_t; #endif +/* Type for key of thread specific data. */ +typedef cthread_key_t __libc_key_t; + /* Define a lock variable NAME with storage class CLASS. The lock must be initialized with __libc_lock_init before it can be used (or define it with __libc_lock_define_initialized, below). Use `extern' for CLASS to @@ -72,19 +75,26 @@ typedef struct __libc_lock_opaque__ __libc_lock_t; (*__save_FCT)(__save_ARG); \ } -/* Use mutexes as once control variables. */ - /* Define once control variable. */ -#define __libc_once_define(CLASS, NAME) \ - CLASS __libc_lock_define_initialized(,NAME) + +struct __libc_once + { + __libc_lock_t lock; + int done; + }; + +#define __libc_once_define(CLASS,NAME) \ + CLASS struct __libc_once NAME = { MUTEX_INITIALZER, 0 } + /* Call handler iff the first call. */ #define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \ do { \ - if (!__libc_lock_trylock(ONCE_CONTROL) { \ + __libc_lock_lock (ONCE_CONTROL.lock); \ + if (!ONCE_CONTROL.done) \ (INIT_FUNCTION) (); \ - __libc_lock_lock(ONCE_CONTROL); \ - } \ + ONCE_CONTROL.done = 1; \ + __libc_lock_unlock (ONCE_CONTROL.lock); \ } while (0) #ifdef _LIBC @@ -93,6 +103,10 @@ typedef struct __libc_lock_opaque__ __libc_lock_t; #define __libc_mutex_unlock __mutex_unlock #endif +#define __libc_key_create(KEY,DEST) cthread_keycreate (KEY) +#define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL) +void *__libc_getspecific (__libc_key_t key); + /* XXX until cthreads supports recursive locks */ #define __libc_lock_define_initialized_recursive __libc_lock_define_initialized #define __libc_lock_init_recursive __libc_lock_init |