Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / src / mutex.cc
blobe6eb6d28a7290359e0e8cb351889f33e2aa929fb
1 // mutex -*- C++ -*-
3 // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 #include <mutex>
27 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
28 #ifndef _GLIBCXX_HAVE_TLS
29 namespace
31 inline std::unique_lock<std::mutex>*&
32 __get_once_functor_lock_ptr()
34 static std::unique_lock<std::mutex>* __once_functor_lock_ptr = 0;
35 return __once_functor_lock_ptr;
38 #endif
40 _GLIBCXX_BEGIN_NAMESPACE(std)
42 #ifdef _GLIBCXX_HAVE_TLS
43 __thread void* __once_callable;
44 __thread void (*__once_call)();
45 #else
46 // Explicit instantiation due to -fno-implicit-instantiation.
47 template class function<void()>;
48 function<void()> __once_functor;
50 mutex&
51 __get_once_mutex()
53 static mutex once_mutex;
54 return once_mutex;
57 // code linked against ABI 3.4.12 and later uses this
58 void
59 __set_once_functor_lock_ptr(unique_lock<mutex>* __ptr)
61 __get_once_functor_lock_ptr() = __ptr;
64 // unsafe - retained for compatibility with ABI 3.4.11
65 unique_lock<mutex>&
66 __get_once_functor_lock()
68 static unique_lock<mutex> once_functor_lock(__get_once_mutex(), defer_lock);
69 return once_functor_lock;
71 #endif
73 extern "C"
75 void __once_proxy()
77 #ifndef _GLIBCXX_HAVE_TLS
78 function<void()> __once_call = std::move(__once_functor);
79 if (unique_lock<mutex>* __lock = __get_once_functor_lock_ptr())
81 // caller is using new ABI and provided lock ptr
82 __get_once_functor_lock_ptr() = 0;
83 __lock->unlock();
85 else
86 __get_once_functor_lock().unlock(); // global lock
87 #endif
88 __once_call();
92 _GLIBCXX_END_NAMESPACE
94 // XXX GLIBCXX_ABI Deprecated
95 // gcc-4.6.0
96 // <mutex> export changes
97 #if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
98 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
99 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
101 namespace __gnu_cxx
103 std::defer_lock_t defer_lock;
104 std::try_to_lock_t try_to_lock;
105 std::adopt_lock_t adopt_lock;
108 #define _GLIBCXX_ASM_SYMVER(cur, old, version) \
109 asm (".symver " #cur "," #old "@@" #version);
111 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10adopt_lockE, _ZSt10adopt_lock, GLIBCXX_3.4.11)
112 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10defer_lockE, _ZSt10defer_lock, GLIBCXX_3.4.11)
113 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx11try_to_lockE, _ZSt11try_to_lock, GLIBCXX_3.4.11)
116 #endif
118 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1