]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/c++11/mutex.cc
[multiple changes]
[thirdparty/gcc.git] / libstdc++-v3 / src / c++11 / mutex.cc
CommitLineData
68a97d24
BK
1// mutex -*- C++ -*-
2
94a86be0 3// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
68a97d24
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
68a97d24
BK
9// any later version.
10
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.
15
748086b7
JJ
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.
68a97d24 19
748086b7
JJ
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/>.
68a97d24
BK
24
25#include <mutex>
26
7b800287 27#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
cca36d72
PC
28#ifndef _GLIBCXX_HAVE_TLS
29namespace
30{
efdb7347
JW
31 inline std::unique_lock<std::mutex>*&
32 __get_once_functor_lock_ptr()
cca36d72 33 {
efdb7347
JW
34 static std::unique_lock<std::mutex>* __once_functor_lock_ptr = 0;
35 return __once_functor_lock_ptr;
cca36d72
PC
36 }
37}
38#endif
39
12ffa228
BK
40namespace std _GLIBCXX_VISIBILITY(default)
41{
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
53dc5044 43
7b800287
CF
44#ifdef _GLIBCXX_HAVE_TLS
45 __thread void* __once_callable;
46 __thread void (*__once_call)();
47#else
99827523 48 // Explicit instantiation due to -fno-implicit-instantiation.
7b800287
CF
49 template class function<void()>;
50 function<void()> __once_functor;
99827523 51
efdb7347
JW
52 mutex&
53 __get_once_mutex()
54 {
55 static mutex once_mutex;
56 return once_mutex;
57 }
58
59 // code linked against ABI 3.4.12 and later uses this
60 void
61 __set_once_functor_lock_ptr(unique_lock<mutex>* __ptr)
62 {
63 __get_once_functor_lock_ptr() = __ptr;
64 }
65
66 // unsafe - retained for compatibility with ABI 3.4.11
cca36d72
PC
67 unique_lock<mutex>&
68 __get_once_functor_lock()
99827523 69 {
efdb7347 70 static unique_lock<mutex> once_functor_lock(__get_once_mutex(), defer_lock);
cca36d72 71 return once_functor_lock;
99827523 72 }
7b800287
CF
73#endif
74
75 extern "C"
76 {
77 void __once_proxy()
78 {
79#ifndef _GLIBCXX_HAVE_TLS
80 function<void()> __once_call = std::move(__once_functor);
efdb7347
JW
81 if (unique_lock<mutex>* __lock = __get_once_functor_lock_ptr())
82 {
83 // caller is using new ABI and provided lock ptr
84 __get_once_functor_lock_ptr() = 0;
85 __lock->unlock();
86 }
87 else
88 __get_once_functor_lock().unlock(); // global lock
7b800287
CF
89#endif
90 __once_call();
91 }
92 }
53dc5044 93
12ffa228
BK
94_GLIBCXX_END_NAMESPACE_VERSION
95} // namespace
68a97d24 96
94a86be0
BK
97// XXX GLIBCXX_ABI Deprecated
98// gcc-4.6.0
99// <mutex> export changes
100#if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
101 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
102 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
103
12ffa228 104namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
94a86be0
BK
105{
106 std::defer_lock_t defer_lock;
107 std::try_to_lock_t try_to_lock;
108 std::adopt_lock_t adopt_lock;
109}
110
111#define _GLIBCXX_ASM_SYMVER(cur, old, version) \
112 asm (".symver " #cur "," #old "@@" #version);
113
114_GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10adopt_lockE, _ZSt10adopt_lock, GLIBCXX_3.4.11)
115_GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10defer_lockE, _ZSt10defer_lock, GLIBCXX_3.4.11)
116_GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx11try_to_lockE, _ZSt11try_to_lock, GLIBCXX_3.4.11)
117
118
119#endif
120
7b800287 121#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1