From: Ulrich Drepper Date: Fri, 8 Aug 1997 00:34:55 +0000 (+0000) Subject: (__libc_once, __libc_once_define): New macros. X-Git-Tag: cvs/glibc-2_0_5pre2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=181e1431e49988869b003be6c562893a13741cf6;p=thirdparty%2Fglibc.git (__libc_once, __libc_once_define): New macros. --- diff --git a/sysdeps/mach/libc-lock.h b/sysdeps/mach/libc-lock.h index cfd176750a5..0b80b1ca513 100644 --- a/sysdeps/mach/libc-lock.h +++ b/sysdeps/mach/libc-lock.h @@ -72,6 +72,20 @@ 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) + +/* Call handler iff the first call. */ +#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \ + do { \ + if (!__libc_lock_trylock(ONCE_CONTROL) { \ + (INIT_FUNCTION) (); \ + __libc_lock_lock(ONCE_CONTROL); \ + } \ + } while (0) #ifdef _LIBC /* We need portable names for some functions. E.g., when they are