]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc
066b08b77de8fc686a3a90de1ec838797813e14b
[thirdparty/gcc.git] / libstdc++-v3 / src / c++11 / compatibility-thread-c++0x.cc
1 // Compatibility symbols for previous versions, C++0x bits -*- C++ -*-
2
3 // Copyright (C) 2009-2016 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.
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
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.
19
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/>.
24
25 #include <bits/c++config.h>
26 #if defined(_GLIBCXX_SHARED)
27 #define _GLIBCXX_ASYNC_ABI_COMPAT
28 #endif
29
30 #include <future>
31 #include <mutex>
32
33 #if __cplusplus < 201103L
34 # error "compatibility-thread-c++0x.cc must be compiled with -std=gnu++0x"
35 #endif
36
37 #define _GLIBCXX_ASM_SYMVER(cur, old, version) \
38 asm (".symver " #cur "," #old "@@@" #version);
39
40 // XXX GLIBCXX_ABI Deprecated
41 // gcc-4.6.0
42 // <future> export changes
43 #if defined(_GLIBCXX_SYMVER_GNU) && defined(_GLIBCXX_SHARED) \
44 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
45 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
46
47 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
48 {
49 const std::error_category* future_category = &std::future_category();
50 }
51
52 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx15future_categoryE, _ZSt15future_category, GLIBCXX_3.4.14)
53
54 #endif
55
56 // XXX GLIBCXX_ABI Deprecated
57 // gcc-4.6.0
58 // <mutex> export changes
59 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
60 #if defined(_GLIBCXX_SYMVER_GNU) && defined(_GLIBCXX_SHARED) \
61 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
62 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
63
64 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
65 {
66 std::defer_lock_t defer_lock;
67 std::try_to_lock_t try_to_lock;
68 std::adopt_lock_t adopt_lock;
69 }
70
71 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10adopt_lockE, _ZSt10adopt_lock, GLIBCXX_3.4.11)
72 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10defer_lockE, _ZSt10defer_lock, GLIBCXX_3.4.11)
73 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx11try_to_lockE, _ZSt11try_to_lock, GLIBCXX_3.4.11)
74
75
76 #endif
77 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
78
79
80 // XXX GLIBCXX_ABI Deprecated
81 // gcc-4.7.0, gcc-4.9.0
82 // <future> export changes
83 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
84 && (ATOMIC_INT_LOCK_FREE > 1)
85 #if defined(_GLIBCXX_SHARED)
86 namespace std _GLIBCXX_VISIBILITY(default)
87 {
88 _GLIBCXX_BEGIN_NAMESPACE_VERSION
89 // Replaced by _State_baseV2 in gcc-4.9.0
90 class __future_base::_State_base
91 {
92 typedef _Ptr<_Result_base> _Ptr_type;
93
94 _Ptr_type _M_result;
95 mutex _M_mutex;
96 condition_variable _M_cond;
97 atomic_flag _M_retrieved;
98 once_flag _M_once;
99 public:
100 virtual ~_State_base();
101 virtual void _M_run_deferred() { }
102 };
103 __future_base::_State_base::~_State_base() { }
104
105 // Replaced by _Async_state_commonV2 in gcc-4.9.0
106 class __future_base::_Async_state_common : public __future_base::_State_base
107 {
108 protected:
109 ~_Async_state_common();
110 virtual void _M_run_deferred() { _M_join(); }
111 void _M_join() { std::call_once(_M_once, &thread::join, ref(_M_thread)); }
112 thread _M_thread;
113 once_flag _M_once;
114 };
115 #if defined(_GLIBCXX_HAVE_TLS)
116 // Replaced with inline definition in gcc-4.8.0
117 __future_base::_Async_state_common::~_Async_state_common() { _M_join(); }
118
119 template<typename _Tp>
120 struct _Maybe_wrap_member_pointer;
121
122 template<typename _Tp, typename _Class>
123 struct _Maybe_wrap_member_pointer<_Tp _Class::*>
124 {
125 typedef _Mem_fn<_Tp _Class::*> type;
126
127 static constexpr type
128 __do_wrap(_Tp _Class::* __pm)
129 { return type(__pm); }
130 };
131
132 template<typename _Signature>
133 struct _Bind_simple;
134
135 template<typename _Callable, typename... _Args>
136 struct _Bind_simple<_Callable(_Args...)>
137 {
138 typedef typename result_of<_Callable(_Args...)>::type result_type;
139
140 template<typename _Tp, typename... _Up>
141 explicit
142 _Bind_simple(_Tp&& __f, _Up&&... __args)
143 : _M_bound(std::forward<_Tp>(__f), std::forward<_Up>(__args)...)
144 { }
145
146 _Bind_simple(const _Bind_simple&) = default;
147 _Bind_simple(_Bind_simple&&) = default;
148
149 result_type
150 operator()()
151 {
152 typedef typename _Build_index_tuple<sizeof...(_Args)>::__type _Indices;
153 return _M_invoke(_Indices());
154 }
155
156 private:
157 template<std::size_t... _Indices>
158 typename result_of<_Callable(_Args...)>::type
159 _M_invoke(_Index_tuple<_Indices...>)
160 {
161 // std::bind always forwards bound arguments as lvalues,
162 // but this type can call functions which only accept rvalues.
163 return std::forward<_Callable>(std::get<0>(_M_bound))(
164 std::forward<_Args>(std::get<_Indices+1>(_M_bound))...);
165 }
166
167 std::tuple<_Callable, _Args...> _M_bound;
168 };
169
170 template<typename _Func, typename... _BoundArgs>
171 struct _Bind_simple_helper
172 {
173 typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
174 __maybe_type;
175 typedef typename __maybe_type::type __func_type;
176 typedef _Bind_simple<__func_type(typename decay<_BoundArgs>::type...)>
177 __type;
178 };
179
180 // Simplified version of std::bind for internal use, without support for
181 // unbound arguments, placeholders or nested bind expressions.
182 template<typename _Callable, typename... _Args>
183 typename _Bind_simple_helper<_Callable, _Args...>::__type
184 __bind_simple(_Callable&& __callable, _Args&&... __args)
185 {
186 typedef _Bind_simple_helper<_Callable, _Args...> __helper_type;
187 typedef typename __helper_type::__maybe_type __maybe_type;
188 typedef typename __helper_type::__type __result_type;
189 return __result_type(
190 __maybe_type::__do_wrap( std::forward<_Callable>(__callable)),
191 std::forward<_Args>(__args)...);
192 }
193
194 // Explicit instantiation due to -fno-implicit-instantiation.
195 template void call_once(once_flag&, void (thread::*&&)(), reference_wrapper<thread>&&);
196 template _Bind_simple_helper<void (thread::*)(), reference_wrapper<thread>>::__type __bind_simple(void (thread::*&&)(), reference_wrapper<thread>&&);
197 #endif // _GLIBCXX_HAVE_TLS
198 _GLIBCXX_END_NAMESPACE_VERSION
199 } // namespace std
200 #endif // _GLIBCXX_SHARED
201 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1