Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
once.h
Go to the documentation of this file.
1
29#include <rw/_defs.h>
30
31
32#ifdef _RWSTD_REENTRANT
33# ifdef _RWSTD_OS_SUNOS
34
35# include <pthread.h>
36# include <thread.h>
37
38# define _RWSTD_THREAD_ONCE(once, func) pthread_once (once, func)
39# define _RWSTD_THREAD_YIELD() thr_yield ()
40# define _RWSTD_ONCE_INIT PTHREAD_ONCE_INIT
41
42typedef pthread_once_t __rw_once_t;
43
44# elif defined (_RWSTD_POSIX_THREADS)
45
46# include <pthread.h>
47
48# ifndef _RWSTD_NO_PTHREAD_ONCE
49
50typedef pthread_once_t __rw_once_t;
51
52# define _RWSTD_THREAD_ONCE(once, func) pthread_once (once, func)
53# define _RWSTD_ONCE_INIT PTHREAD_ONCE_INIT
54
55# else // if defined (_RWSTD_NO_PTHREAD_ONCE)
56
58
59struct __rw_once_t {
60 pthread_mutex_t _C_mutex;
61 int _C_init;
62};
63
64} // namespace __rw
65
66# define _RWSTD_ONCE_INIT { PTHREAD_MUTEX_INITIALIZER, -1 }
67
68# endif // _RWSTD_NO_PTHREAD_ONCE
69
70# ifndef _RWSTD_NO_SCHED_YIELD
71# define _RWSTD_THREAD_YIELD() sched_yield ()
72# endif // _RWSTD_NO_SCHED_YIELD
73# elif defined (_RWSTD_DCE_THREADS)
74
75# if defined (_RWSTD_NO_DCE_PTHREAD_H)
76# include <pthread.h>
77# else
78# include <dce/pthread.h>
79# endif
80
82
83typedef pthread_once_t __rw_once_t;
84
85} // namespace __rw
86
87# define _RWSTD_THREAD_ONCE(once, func) pthread_once (once, func)
88# define _RWSTD_THREAD_YIELD() pthread_yield ()
89# define _RWSTD_ONCE_INIT PTHREAD_ONCE_INIT
90
91# elif defined (_WIN32)
92
93# include <windows.h>
94
96
97struct __rw_once_t { int _C_init; };
98
99} // namespace __rw
100
101# define _RWSTD_THREAD_YIELD() Sleep (0)
102# define _RWSTD_ONCE_INIT { 0 }
103# else // !_WIN32
104
106
107struct __rw_once_t { int _C_init; };
108
109} // namespace __rw
110
111# define _RWSTD_ONCE_INIT { 0 }
112# endif // _WIN32
113#else // if !defined (_RWSTD_REENTRANT)
114
116
117struct __rw_once_t { int _C_init; };
118
119} // namespace __rw
120
121 // defined to a non-zero value to help detect uninitialized
122 // __rw_once_t objects
123# define _RWSTD_ONCE_INIT { -1 }
124#endif // _RWSTD_REENTRANT
125
126
127#ifndef _RWSTD_THREAD_YIELD
128# define _RWSTD_THREAD_YIELD() (void)0
129#endif // _RWSTD_THREAD_YIELD
130
131
133
134extern "C" {
135
136#if !defined (_RWSTD_MSVC) || !defined (_RWSTD_REENTRANT)
137
139__rw_once (__rw_once_t*, void (*)());
140
141#else // _RWSTD_MSVC && _RWSTD_REENTRANT
142
143// MSVC by default assumes that functions with C linkage don't
144// throw exceptions and issues warning "function assumed not
145// to throw an exception but does". Specifying an exception
146// specification using the throw(...) extension prevents this
147// problem.
148// Note: functions with C linkage passed as an argument to
149// __rw_once() should also be declared with the appropriate
150// exception specification if it throws an exception in order
151// to avoid resource leaks due to destructors of objects with
152// auto storage duration not being run otherwise.
154__rw_once (__rw_once_t*, void (*)() throw (...)) throw (...);
155
156#endif // !_RWSTD_MSVC || !_RWSTD_REENTRANT
157
158} // extern "C"
159
160
161} // namespace __rw
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567