annotate libstdc++-v3/libsupc++/guard.cc @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // Copyright (C) 2002-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
2 //
kono
parents:
diff changeset
3 // This file is part of GCC.
kono
parents:
diff changeset
4 //
kono
parents:
diff changeset
5 // GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
6 // it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
7 // the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
8 // any later version.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 // GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
13 // GNU General Public License for more details.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
16 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
17 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
20 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
21 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
22 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 // Written by Mark Mitchell, CodeSourcery LLC, <mark@codesourcery.com>
kono
parents:
diff changeset
25 // Thread support written by Jason Merrill, Red Hat Inc. <jason@redhat.com>
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 #include <bits/c++config.h>
kono
parents:
diff changeset
28 #include <cxxabi.h>
kono
parents:
diff changeset
29 #include <exception>
kono
parents:
diff changeset
30 #include <new>
kono
parents:
diff changeset
31 #include <ext/atomicity.h>
kono
parents:
diff changeset
32 #include <ext/concurrence.h>
kono
parents:
diff changeset
33 #include <bits/atomic_lockfree_defines.h>
kono
parents:
diff changeset
34 #if defined(__GTHREADS) && defined(__GTHREAD_HAS_COND) \
kono
parents:
diff changeset
35 && (ATOMIC_INT_LOCK_FREE > 1) && defined(_GLIBCXX_HAVE_LINUX_FUTEX)
kono
parents:
diff changeset
36 # include <climits>
kono
parents:
diff changeset
37 # include <syscall.h>
kono
parents:
diff changeset
38 # include <unistd.h>
kono
parents:
diff changeset
39 # define _GLIBCXX_USE_FUTEX
kono
parents:
diff changeset
40 # define _GLIBCXX_FUTEX_WAIT 0
kono
parents:
diff changeset
41 # define _GLIBCXX_FUTEX_WAKE 1
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 // The IA64/generic ABI uses the first byte of the guard variable.
kono
parents:
diff changeset
45 // The ARM EABI uses the least significant bit.
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 // Thread-safe static local initialization support.
kono
parents:
diff changeset
48 #ifdef __GTHREADS
kono
parents:
diff changeset
49 # ifndef _GLIBCXX_USE_FUTEX
kono
parents:
diff changeset
50 namespace
kono
parents:
diff changeset
51 {
kono
parents:
diff changeset
52 // A single mutex controlling all static initializations.
kono
parents:
diff changeset
53 static __gnu_cxx::__recursive_mutex* static_mutex;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 typedef char fake_recursive_mutex[sizeof(__gnu_cxx::__recursive_mutex)]
kono
parents:
diff changeset
56 __attribute__ ((aligned(__alignof__(__gnu_cxx::__recursive_mutex))));
kono
parents:
diff changeset
57 fake_recursive_mutex fake_mutex;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 static void init()
kono
parents:
diff changeset
60 { static_mutex = new (&fake_mutex) __gnu_cxx::__recursive_mutex(); }
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 __gnu_cxx::__recursive_mutex&
kono
parents:
diff changeset
63 get_static_mutex()
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 static __gthread_once_t once = __GTHREAD_ONCE_INIT;
kono
parents:
diff changeset
66 __gthread_once(&once, init);
kono
parents:
diff changeset
67 return *static_mutex;
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 // Simple wrapper for exception safety.
kono
parents:
diff changeset
71 struct mutex_wrapper
kono
parents:
diff changeset
72 {
kono
parents:
diff changeset
73 bool unlock;
kono
parents:
diff changeset
74 mutex_wrapper() : unlock(true)
kono
parents:
diff changeset
75 { get_static_mutex().lock(); }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 ~mutex_wrapper()
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 if (unlock)
kono
parents:
diff changeset
80 static_mutex->unlock();
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82 };
kono
parents:
diff changeset
83 }
kono
parents:
diff changeset
84 # endif
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 # if defined(__GTHREAD_HAS_COND) && !defined(_GLIBCXX_USE_FUTEX)
kono
parents:
diff changeset
87 namespace
kono
parents:
diff changeset
88 {
kono
parents:
diff changeset
89 // A single condition variable controlling all static initializations.
kono
parents:
diff changeset
90 static __gnu_cxx::__cond* static_cond;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 // using a fake type to avoid initializing a static class.
kono
parents:
diff changeset
93 typedef char fake_cond_t[sizeof(__gnu_cxx::__cond)]
kono
parents:
diff changeset
94 __attribute__ ((aligned(__alignof__(__gnu_cxx::__cond))));
kono
parents:
diff changeset
95 fake_cond_t fake_cond;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 static void init_static_cond()
kono
parents:
diff changeset
98 { static_cond = new (&fake_cond) __gnu_cxx::__cond(); }
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 __gnu_cxx::__cond&
kono
parents:
diff changeset
101 get_static_cond()
kono
parents:
diff changeset
102 {
kono
parents:
diff changeset
103 static __gthread_once_t once = __GTHREAD_ONCE_INIT;
kono
parents:
diff changeset
104 __gthread_once(&once, init_static_cond);
kono
parents:
diff changeset
105 return *static_cond;
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107 }
kono
parents:
diff changeset
108 # endif
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 # ifndef _GLIBCXX_GUARD_TEST_AND_ACQUIRE
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 // Test the guard variable with a memory load with
kono
parents:
diff changeset
113 // acquire semantics.
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 inline bool
kono
parents:
diff changeset
116 __test_and_acquire (__cxxabiv1::__guard *g)
kono
parents:
diff changeset
117 {
kono
parents:
diff changeset
118 unsigned char __c;
kono
parents:
diff changeset
119 unsigned char *__p = reinterpret_cast<unsigned char *>(g);
kono
parents:
diff changeset
120 __atomic_load (__p, &__c, __ATOMIC_ACQUIRE);
kono
parents:
diff changeset
121 (void) __p;
kono
parents:
diff changeset
122 return _GLIBCXX_GUARD_TEST(&__c);
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124 # define _GLIBCXX_GUARD_TEST_AND_ACQUIRE(G) __test_and_acquire (G)
kono
parents:
diff changeset
125 # endif
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 # ifndef _GLIBCXX_GUARD_SET_AND_RELEASE
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 // Set the guard variable to 1 with memory order release semantics.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 inline void
kono
parents:
diff changeset
132 __set_and_release (__cxxabiv1::__guard *g)
kono
parents:
diff changeset
133 {
kono
parents:
diff changeset
134 unsigned char *__p = reinterpret_cast<unsigned char *>(g);
kono
parents:
diff changeset
135 unsigned char val = 1;
kono
parents:
diff changeset
136 __atomic_store (__p, &val, __ATOMIC_RELEASE);
kono
parents:
diff changeset
137 (void) __p;
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139 # define _GLIBCXX_GUARD_SET_AND_RELEASE(G) __set_and_release (G)
kono
parents:
diff changeset
140 # endif
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 #else /* !__GTHREADS */
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 # undef _GLIBCXX_GUARD_TEST_AND_ACQUIRE
kono
parents:
diff changeset
145 # undef _GLIBCXX_GUARD_SET_AND_RELEASE
kono
parents:
diff changeset
146 # define _GLIBCXX_GUARD_SET_AND_RELEASE(G) _GLIBCXX_GUARD_SET (G)
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 #endif /* __GTHREADS */
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 //
kono
parents:
diff changeset
151 // Here are C++ run-time routines for guarded initialization of static
kono
parents:
diff changeset
152 // variables. There are 4 scenarios under which these routines are called:
kono
parents:
diff changeset
153 //
kono
parents:
diff changeset
154 // 1. Threads not supported (__GTHREADS not defined)
kono
parents:
diff changeset
155 // 2. Threads are supported but not enabled at run-time.
kono
parents:
diff changeset
156 // 3. Threads enabled at run-time but __gthreads_* are not fully POSIX.
kono
parents:
diff changeset
157 // 4. Threads enabled at run-time and __gthreads_* support all POSIX threads
kono
parents:
diff changeset
158 // primitives we need here.
kono
parents:
diff changeset
159 //
kono
parents:
diff changeset
160 // The old code supported scenarios 1-3 but was broken since it used a global
kono
parents:
diff changeset
161 // mutex for all threads and had the mutex locked during the whole duration of
kono
parents:
diff changeset
162 // initialization of a guarded static variable. The following created a
kono
parents:
diff changeset
163 // dead-lock with the old code.
kono
parents:
diff changeset
164 //
kono
parents:
diff changeset
165 // Thread 1 acquires the global mutex.
kono
parents:
diff changeset
166 // Thread 1 starts initializing static variable.
kono
parents:
diff changeset
167 // Thread 1 creates thread 2 during initialization.
kono
parents:
diff changeset
168 // Thread 2 attempts to acquire mutex to initialize another variable.
kono
parents:
diff changeset
169 // Thread 2 blocks since thread 1 is locking the mutex.
kono
parents:
diff changeset
170 // Thread 1 waits for result from thread 2 and also blocks. A deadlock.
kono
parents:
diff changeset
171 //
kono
parents:
diff changeset
172 // The new code here can handle this situation and thus is more robust. However,
kono
parents:
diff changeset
173 // we need to use the POSIX thread condition variable, which is not supported
kono
parents:
diff changeset
174 // in all platforms, notably older versions of Microsoft Windows. The gthr*.h
kono
parents:
diff changeset
175 // headers define a symbol __GTHREAD_HAS_COND for platforms that support POSIX
kono
parents:
diff changeset
176 // like condition variables. For platforms that do not support condition
kono
parents:
diff changeset
177 // variables, we need to fall back to the old code.
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 // If _GLIBCXX_USE_FUTEX, no global mutex or condition variable is used,
kono
parents:
diff changeset
180 // only atomic operations are used together with futex syscall.
kono
parents:
diff changeset
181 // Valid values of the first integer in guard are:
kono
parents:
diff changeset
182 // 0 No thread encountered the guarded init
kono
parents:
diff changeset
183 // yet or it has been aborted.
kono
parents:
diff changeset
184 // _GLIBCXX_GUARD_BIT The guarded static var has been successfully
kono
parents:
diff changeset
185 // initialized.
kono
parents:
diff changeset
186 // _GLIBCXX_GUARD_PENDING_BIT The guarded static var is being initialized
kono
parents:
diff changeset
187 // and no other thread is waiting for its
kono
parents:
diff changeset
188 // initialization.
kono
parents:
diff changeset
189 // (_GLIBCXX_GUARD_PENDING_BIT The guarded static var is being initialized
kono
parents:
diff changeset
190 // | _GLIBCXX_GUARD_WAITING_BIT) and some other threads are waiting until
kono
parents:
diff changeset
191 // it is initialized.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 namespace __cxxabiv1
kono
parents:
diff changeset
194 {
kono
parents:
diff changeset
195 #ifdef _GLIBCXX_USE_FUTEX
kono
parents:
diff changeset
196 namespace
kono
parents:
diff changeset
197 {
kono
parents:
diff changeset
198 static inline int __guard_test_bit (const int __byte, const int __val)
kono
parents:
diff changeset
199 {
kono
parents:
diff changeset
200 union { int __i; char __c[sizeof (int)]; } __u = { 0 };
kono
parents:
diff changeset
201 __u.__c[__byte] = __val;
kono
parents:
diff changeset
202 return __u.__i;
kono
parents:
diff changeset
203 }
kono
parents:
diff changeset
204 }
kono
parents:
diff changeset
205 #endif
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 static inline int
kono
parents:
diff changeset
208 init_in_progress_flag(__guard* g)
kono
parents:
diff changeset
209 { return ((char *)g)[1]; }
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 static inline void
kono
parents:
diff changeset
212 set_init_in_progress_flag(__guard* g, int v)
kono
parents:
diff changeset
213 { ((char *)g)[1] = v; }
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 static inline void
kono
parents:
diff changeset
216 throw_recursive_init_exception()
kono
parents:
diff changeset
217 {
kono
parents:
diff changeset
218 #if __cpp_exceptions
kono
parents:
diff changeset
219 throw __gnu_cxx::recursive_init_error();
kono
parents:
diff changeset
220 #else
kono
parents:
diff changeset
221 // Use __builtin_trap so we don't require abort().
kono
parents:
diff changeset
222 __builtin_trap();
kono
parents:
diff changeset
223 #endif
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 // acquire() is a helper function used to acquire guard if thread support is
kono
parents:
diff changeset
227 // not compiled in or is compiled in but not enabled at run-time.
kono
parents:
diff changeset
228 static int
kono
parents:
diff changeset
229 acquire(__guard *g)
kono
parents:
diff changeset
230 {
kono
parents:
diff changeset
231 // Quit if the object is already initialized.
kono
parents:
diff changeset
232 if (_GLIBCXX_GUARD_TEST(g))
kono
parents:
diff changeset
233 return 0;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 if (init_in_progress_flag(g))
kono
parents:
diff changeset
236 throw_recursive_init_exception();
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 set_init_in_progress_flag(g, 1);
kono
parents:
diff changeset
239 return 1;
kono
parents:
diff changeset
240 }
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 extern "C"
kono
parents:
diff changeset
243 int __cxa_guard_acquire (__guard *g)
kono
parents:
diff changeset
244 {
kono
parents:
diff changeset
245 #ifdef __GTHREADS
kono
parents:
diff changeset
246 // If the target can reorder loads, we need to insert a read memory
kono
parents:
diff changeset
247 // barrier so that accesses to the guarded variable happen after the
kono
parents:
diff changeset
248 // guard test.
kono
parents:
diff changeset
249 if (_GLIBCXX_GUARD_TEST_AND_ACQUIRE (g))
kono
parents:
diff changeset
250 return 0;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 # ifdef _GLIBCXX_USE_FUTEX
kono
parents:
diff changeset
253 // If __atomic_* and futex syscall are supported, don't use any global
kono
parents:
diff changeset
254 // mutex.
kono
parents:
diff changeset
255 if (__gthread_active_p ())
kono
parents:
diff changeset
256 {
kono
parents:
diff changeset
257 int *gi = (int *) (void *) g;
kono
parents:
diff changeset
258 const int guard_bit = _GLIBCXX_GUARD_BIT;
kono
parents:
diff changeset
259 const int pending_bit = _GLIBCXX_GUARD_PENDING_BIT;
kono
parents:
diff changeset
260 const int waiting_bit = _GLIBCXX_GUARD_WAITING_BIT;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 while (1)
kono
parents:
diff changeset
263 {
kono
parents:
diff changeset
264 int expected(0);
kono
parents:
diff changeset
265 if (__atomic_compare_exchange_n(gi, &expected, pending_bit, false,
kono
parents:
diff changeset
266 __ATOMIC_ACQ_REL,
kono
parents:
diff changeset
267 __ATOMIC_ACQUIRE))
kono
parents:
diff changeset
268 {
kono
parents:
diff changeset
269 // This thread should do the initialization.
kono
parents:
diff changeset
270 return 1;
kono
parents:
diff changeset
271 }
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 if (expected == guard_bit)
kono
parents:
diff changeset
274 {
kono
parents:
diff changeset
275 // Already initialized.
kono
parents:
diff changeset
276 return 0;
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 if (expected == pending_bit)
kono
parents:
diff changeset
280 {
kono
parents:
diff changeset
281 // Use acquire here.
kono
parents:
diff changeset
282 int newv = expected | waiting_bit;
kono
parents:
diff changeset
283 if (!__atomic_compare_exchange_n(gi, &expected, newv, false,
kono
parents:
diff changeset
284 __ATOMIC_ACQ_REL,
kono
parents:
diff changeset
285 __ATOMIC_ACQUIRE))
kono
parents:
diff changeset
286 {
kono
parents:
diff changeset
287 if (expected == guard_bit)
kono
parents:
diff changeset
288 {
kono
parents:
diff changeset
289 // Make a thread that failed to set the
kono
parents:
diff changeset
290 // waiting bit exit the function earlier,
kono
parents:
diff changeset
291 // if it detects that another thread has
kono
parents:
diff changeset
292 // successfully finished initialising.
kono
parents:
diff changeset
293 return 0;
kono
parents:
diff changeset
294 }
kono
parents:
diff changeset
295 if (expected == 0)
kono
parents:
diff changeset
296 continue;
kono
parents:
diff changeset
297 }
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 expected = newv;
kono
parents:
diff changeset
300 }
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAIT, expected, 0);
kono
parents:
diff changeset
303 }
kono
parents:
diff changeset
304 }
kono
parents:
diff changeset
305 # else
kono
parents:
diff changeset
306 if (__gthread_active_p ())
kono
parents:
diff changeset
307 {
kono
parents:
diff changeset
308 mutex_wrapper mw;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 while (1) // When this loop is executing, mutex is locked.
kono
parents:
diff changeset
311 {
kono
parents:
diff changeset
312 # ifdef __GTHREAD_HAS_COND
kono
parents:
diff changeset
313 // The static is already initialized.
kono
parents:
diff changeset
314 if (_GLIBCXX_GUARD_TEST(g))
kono
parents:
diff changeset
315 return 0; // The mutex will be unlocked via wrapper
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 if (init_in_progress_flag(g))
kono
parents:
diff changeset
318 {
kono
parents:
diff changeset
319 // The guarded static is currently being initialized by
kono
parents:
diff changeset
320 // another thread, so we release mutex and wait for the
kono
parents:
diff changeset
321 // condition variable. We will lock the mutex again after
kono
parents:
diff changeset
322 // this.
kono
parents:
diff changeset
323 get_static_cond().wait_recursive(&get_static_mutex());
kono
parents:
diff changeset
324 }
kono
parents:
diff changeset
325 else
kono
parents:
diff changeset
326 {
kono
parents:
diff changeset
327 set_init_in_progress_flag(g, 1);
kono
parents:
diff changeset
328 return 1; // The mutex will be unlocked via wrapper.
kono
parents:
diff changeset
329 }
kono
parents:
diff changeset
330 # else
kono
parents:
diff changeset
331 // This provides compatibility with older systems not supporting
kono
parents:
diff changeset
332 // POSIX like condition variables.
kono
parents:
diff changeset
333 if (acquire(g))
kono
parents:
diff changeset
334 {
kono
parents:
diff changeset
335 mw.unlock = false;
kono
parents:
diff changeset
336 return 1; // The mutex still locked.
kono
parents:
diff changeset
337 }
kono
parents:
diff changeset
338 return 0; // The mutex will be unlocked via wrapper.
kono
parents:
diff changeset
339 # endif
kono
parents:
diff changeset
340 }
kono
parents:
diff changeset
341 }
kono
parents:
diff changeset
342 # endif
kono
parents:
diff changeset
343 #endif
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 return acquire (g);
kono
parents:
diff changeset
346 }
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 extern "C"
kono
parents:
diff changeset
349 void __cxa_guard_abort (__guard *g) throw ()
kono
parents:
diff changeset
350 {
kono
parents:
diff changeset
351 #ifdef _GLIBCXX_USE_FUTEX
kono
parents:
diff changeset
352 // If __atomic_* and futex syscall are supported, don't use any global
kono
parents:
diff changeset
353 // mutex.
kono
parents:
diff changeset
354 if (__gthread_active_p ())
kono
parents:
diff changeset
355 {
kono
parents:
diff changeset
356 int *gi = (int *) (void *) g;
kono
parents:
diff changeset
357 const int waiting_bit = _GLIBCXX_GUARD_WAITING_BIT;
kono
parents:
diff changeset
358 int old = __atomic_exchange_n (gi, 0, __ATOMIC_ACQ_REL);
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 if ((old & waiting_bit) != 0)
kono
parents:
diff changeset
361 syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAKE, INT_MAX);
kono
parents:
diff changeset
362 return;
kono
parents:
diff changeset
363 }
kono
parents:
diff changeset
364 #elif defined(__GTHREAD_HAS_COND)
kono
parents:
diff changeset
365 if (__gthread_active_p())
kono
parents:
diff changeset
366 {
kono
parents:
diff changeset
367 mutex_wrapper mw;
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 set_init_in_progress_flag(g, 0);
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 // If we abort, we still need to wake up all other threads waiting for
kono
parents:
diff changeset
372 // the condition variable.
kono
parents:
diff changeset
373 get_static_cond().broadcast();
kono
parents:
diff changeset
374 return;
kono
parents:
diff changeset
375 }
kono
parents:
diff changeset
376 #endif
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 set_init_in_progress_flag(g, 0);
kono
parents:
diff changeset
379 #if defined(__GTHREADS) && !defined(__GTHREAD_HAS_COND)
kono
parents:
diff changeset
380 // This provides compatibility with older systems not supporting POSIX like
kono
parents:
diff changeset
381 // condition variables.
kono
parents:
diff changeset
382 if (__gthread_active_p ())
kono
parents:
diff changeset
383 static_mutex->unlock();
kono
parents:
diff changeset
384 #endif
kono
parents:
diff changeset
385 }
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 extern "C"
kono
parents:
diff changeset
388 void __cxa_guard_release (__guard *g) throw ()
kono
parents:
diff changeset
389 {
kono
parents:
diff changeset
390 #ifdef _GLIBCXX_USE_FUTEX
kono
parents:
diff changeset
391 // If __atomic_* and futex syscall are supported, don't use any global
kono
parents:
diff changeset
392 // mutex.
kono
parents:
diff changeset
393 if (__gthread_active_p ())
kono
parents:
diff changeset
394 {
kono
parents:
diff changeset
395 int *gi = (int *) (void *) g;
kono
parents:
diff changeset
396 const int guard_bit = _GLIBCXX_GUARD_BIT;
kono
parents:
diff changeset
397 const int waiting_bit = _GLIBCXX_GUARD_WAITING_BIT;
kono
parents:
diff changeset
398 int old = __atomic_exchange_n (gi, guard_bit, __ATOMIC_ACQ_REL);
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 if ((old & waiting_bit) != 0)
kono
parents:
diff changeset
401 syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAKE, INT_MAX);
kono
parents:
diff changeset
402 return;
kono
parents:
diff changeset
403 }
kono
parents:
diff changeset
404 #elif defined(__GTHREAD_HAS_COND)
kono
parents:
diff changeset
405 if (__gthread_active_p())
kono
parents:
diff changeset
406 {
kono
parents:
diff changeset
407 mutex_wrapper mw;
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 set_init_in_progress_flag(g, 0);
kono
parents:
diff changeset
410 _GLIBCXX_GUARD_SET_AND_RELEASE(g);
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 get_static_cond().broadcast();
kono
parents:
diff changeset
413 return;
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415 #endif
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 set_init_in_progress_flag(g, 0);
kono
parents:
diff changeset
418 _GLIBCXX_GUARD_SET_AND_RELEASE (g);
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 #if defined(__GTHREADS) && !defined(__GTHREAD_HAS_COND)
kono
parents:
diff changeset
421 // This provides compatibility with older systems not supporting POSIX like
kono
parents:
diff changeset
422 // condition variables.
kono
parents:
diff changeset
423 if (__gthread_active_p())
kono
parents:
diff changeset
424 static_mutex->unlock();
kono
parents:
diff changeset
425 #endif
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427 }