tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
thr_once and !_REENTRANT libc
Hi all,
the attached patch allows code to use thread-safe initialisation without
having to worry about _REENTRANT. It should result in ~the same amount
of code as hand-roled solutions without requiring code duplication.
Joerg
Index: reentrant.h
===================================================================
RCS file: /btrfs/repo/netbsd/src/lib/libc/include/reentrant.h,v
retrieving revision 1.14
diff -u -p -r1.14 reentrant.h
--- reentrant.h 11 Jan 2009 02:46:28 -0000 1.14
+++ reentrant.h 1 Jun 2012 17:35:16 -0000
@@ -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 @@ __END_DECLS
#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