]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(__libc_once, __libc_once_define): New macros.
authorUlrich Drepper <drepper@redhat.com>
Fri, 8 Aug 1997 00:34:55 +0000 (00:34 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 8 Aug 1997 00:34:55 +0000 (00:34 +0000)
sysdeps/mach/libc-lock.h

index cfd176750a5f101f5ce474ef41118dc3bf7e69ed..0b80b1ca513e340154f2e76f55e223a5c733cdd6 100644 (file)
@@ -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