Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/include Provide a usable thr_once for !_REENTRANT



details:   https://anonhg.NetBSD.org/src/rev/6475bda8f105
branches:  trunk
changeset: 779577:6475bda8f105
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sun Jun 03 21:27:30 2012 +0000

description:
Provide a usable thr_once for !_REENTRANT

diffstat:

 lib/libc/include/reentrant.h |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (44 lines):

diff -r ff357908484c -r 6475bda8f105 lib/libc/include/reentrant.h
--- a/lib/libc/include/reentrant.h      Sun Jun 03 21:21:45 2012 +0000
+++ b/lib/libc/include/reentrant.h      Sun Jun 03 21:27:30 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: reentrant.h,v 1.14 2009/01/11 02:46:28 christos Exp $  */
+/*     $NetBSD: reentrant.h,v 1.15 2012/06/03 21:27:30 joerg Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc.
@@ -84,8 +84,6 @@
  *
  */
 
-#ifdef _REENTRANT
-
 /*
  * Abstract thread interface for thread-safe libraries.  These routines
  * will use stubs in libc if the application is not linked against the
@@ -124,6 +122,8 @@
 #define        once_t                  pthread_once_t
 #define        ONCE_INITIALIZER        PTHREAD_ONCE_INIT
 
+#ifdef _REENTRANT
+
 #ifndef __LIBC_THREAD_STUBS
 
 __BEGIN_DECLS
@@ -254,7 +254,15 @@
 #define        thr_getspecific(k)
 #define        thr_keydelete(k)
 
-#define        thr_once(o, f)
+static inline int
+thr_once(once_t *once_control, void (*routine)(void))
+{
+       if (__predict_false(once_control->pto_done == 0)) {
+               (*routine)();
+               once_control->pto_done = 1;
+       }
+       return 0;
+}
 #define        thr_sigsetmask(f, n, o)
 #define        thr_self()
 #define        thr_errno()



Home | Main Index | Thread Index | Old Index