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