1*38fd1498Szrj // Compatibility symbols for previous versions, C++0x bits -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj // Copyright (C) 2009-2018 Free Software Foundation, Inc. 4*38fd1498Szrj // 5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj // software; you can redistribute it and/or modify it under the 7*38fd1498Szrj // terms of the GNU General Public License as published by the 8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj // any later version. 10*38fd1498Szrj 11*38fd1498Szrj // This library is distributed in the hope that it will be useful, 12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj // GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj // 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj // You should have received a copy of the GNU General Public License and 21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj // <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj #include <bits/c++config.h> 26*38fd1498Szrj #if defined(_GLIBCXX_SHARED) 27*38fd1498Szrj #define _GLIBCXX_ASYNC_ABI_COMPAT 28*38fd1498Szrj #endif 29*38fd1498Szrj 30*38fd1498Szrj #include <future> 31*38fd1498Szrj #include <mutex> 32*38fd1498Szrj #include <functional> 33*38fd1498Szrj 34*38fd1498Szrj #if __cplusplus < 201103L 35*38fd1498Szrj # error "compatibility-thread-c++0x.cc must be compiled with -std=gnu++0x" 36*38fd1498Szrj #endif 37*38fd1498Szrj 38*38fd1498Szrj #define _GLIBCXX_ASM_SYMVER(cur, old, version) \ 39*38fd1498Szrj asm (".symver " #cur "," #old "@@@" #version); 40*38fd1498Szrj 41*38fd1498Szrj // XXX GLIBCXX_ABI Deprecated 42*38fd1498Szrj // gcc-4.6.0 43*38fd1498Szrj // <future> export changes 44*38fd1498Szrj #if defined(_GLIBCXX_SYMVER_GNU) && defined(_GLIBCXX_SHARED) \ 45*38fd1498Szrj && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \ 46*38fd1498Szrj && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT) 47*38fd1498Szrj 48*38fd1498Szrj namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 49*38fd1498Szrj { 50*38fd1498Szrj const std::error_category* future_category = &std::future_category(); 51*38fd1498Szrj } 52*38fd1498Szrj 53*38fd1498Szrj _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx15future_categoryE, _ZSt15future_category, GLIBCXX_3.4.14) 54*38fd1498Szrj 55*38fd1498Szrj #endif 56*38fd1498Szrj 57*38fd1498Szrj // XXX GLIBCXX_ABI Deprecated 58*38fd1498Szrj // gcc-4.6.0 59*38fd1498Szrj // <mutex> export changes 60*38fd1498Szrj #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) 61*38fd1498Szrj #if defined(_GLIBCXX_SYMVER_GNU) && defined(_GLIBCXX_SHARED) \ 62*38fd1498Szrj && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \ 63*38fd1498Szrj && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT) 64*38fd1498Szrj 65*38fd1498Szrj namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 66*38fd1498Szrj { 67*38fd1498Szrj std::defer_lock_t defer_lock; 68*38fd1498Szrj std::try_to_lock_t try_to_lock; 69*38fd1498Szrj std::adopt_lock_t adopt_lock; 70*38fd1498Szrj } 71*38fd1498Szrj 72*38fd1498Szrj _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10adopt_lockE, _ZSt10adopt_lock, GLIBCXX_3.4.11) 73*38fd1498Szrj _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx10defer_lockE, _ZSt10defer_lock, GLIBCXX_3.4.11) 74*38fd1498Szrj _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx11try_to_lockE, _ZSt11try_to_lock, GLIBCXX_3.4.11) 75*38fd1498Szrj 76*38fd1498Szrj 77*38fd1498Szrj #endif 78*38fd1498Szrj #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 79*38fd1498Szrj 80*38fd1498Szrj 81*38fd1498Szrj // XXX GLIBCXX_ABI Deprecated 82*38fd1498Szrj // gcc-4.7.0, gcc-4.9.0 83*38fd1498Szrj // <future> export changes 84*38fd1498Szrj #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ 85*38fd1498Szrj && (ATOMIC_INT_LOCK_FREE > 1) 86*38fd1498Szrj #if defined(_GLIBCXX_SHARED) 87*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 88*38fd1498Szrj { 89*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 90*38fd1498Szrj // Replaced by _State_baseV2 in gcc-4.9.0 91*38fd1498Szrj class __future_base::_State_base 92*38fd1498Szrj { 93*38fd1498Szrj typedef _Ptr<_Result_base> _Ptr_type; 94*38fd1498Szrj 95*38fd1498Szrj _Ptr_type _M_result; 96*38fd1498Szrj mutex _M_mutex; 97*38fd1498Szrj condition_variable _M_cond; 98*38fd1498Szrj atomic_flag _M_retrieved; 99*38fd1498Szrj once_flag _M_once; 100*38fd1498Szrj public: 101*38fd1498Szrj virtual ~_State_base(); _M_run_deferred()102*38fd1498Szrj virtual void _M_run_deferred() { } 103*38fd1498Szrj }; ~_State_base()104*38fd1498Szrj __future_base::_State_base::~_State_base() { } 105*38fd1498Szrj 106*38fd1498Szrj // Replaced by _Async_state_commonV2 in gcc-4.9.0 107*38fd1498Szrj class __future_base::_Async_state_common : public __future_base::_State_base 108*38fd1498Szrj { 109*38fd1498Szrj protected: 110*38fd1498Szrj ~_Async_state_common(); _M_run_deferred()111*38fd1498Szrj virtual void _M_run_deferred() { _M_join(); } _M_join()112*38fd1498Szrj void _M_join() { std::call_once(_M_once, &thread::join, ref(_M_thread)); } 113*38fd1498Szrj thread _M_thread; 114*38fd1498Szrj once_flag _M_once; 115*38fd1498Szrj }; 116*38fd1498Szrj #if defined(_GLIBCXX_HAVE_TLS) 117*38fd1498Szrj // Replaced with inline definition in gcc-4.8.0 ~_Async_state_common()118*38fd1498Szrj __future_base::_Async_state_common::~_Async_state_common() { _M_join(); } 119*38fd1498Szrj 120*38fd1498Szrj template<typename _Tp> 121*38fd1498Szrj struct _Maybe_wrap_member_pointer; 122*38fd1498Szrj 123*38fd1498Szrj template<typename _Tp, typename _Class> 124*38fd1498Szrj struct _Maybe_wrap_member_pointer<_Tp _Class::*> 125*38fd1498Szrj { 126*38fd1498Szrj typedef _Mem_fn<_Tp _Class::*> type; 127*38fd1498Szrj 128*38fd1498Szrj static constexpr type __do_wrapstd::_Maybe_wrap_member_pointer129*38fd1498Szrj __do_wrap(_Tp _Class::* __pm) 130*38fd1498Szrj { return type(__pm); } 131*38fd1498Szrj }; 132*38fd1498Szrj 133*38fd1498Szrj template<typename _Signature> 134*38fd1498Szrj struct _Bind_simple; 135*38fd1498Szrj 136*38fd1498Szrj template<typename _Callable, typename... _Args> 137*38fd1498Szrj struct _Bind_simple<_Callable(_Args...)> 138*38fd1498Szrj { 139*38fd1498Szrj typedef typename result_of<_Callable(_Args...)>::type result_type; 140*38fd1498Szrj 141*38fd1498Szrj template<typename _Tp, typename... _Up> 142*38fd1498Szrj explicit _Bind_simplestd::_Bind_simple143*38fd1498Szrj _Bind_simple(_Tp&& __f, _Up&&... __args) 144*38fd1498Szrj : _M_bound(std::forward<_Tp>(__f), std::forward<_Up>(__args)...) 145*38fd1498Szrj { } 146*38fd1498Szrj 147*38fd1498Szrj _Bind_simple(const _Bind_simple&) = default; 148*38fd1498Szrj _Bind_simple(_Bind_simple&&) = default; 149*38fd1498Szrj 150*38fd1498Szrj result_type operator ()std::_Bind_simple151*38fd1498Szrj operator()() 152*38fd1498Szrj { 153*38fd1498Szrj typedef typename _Build_index_tuple<sizeof...(_Args)>::__type _Indices; 154*38fd1498Szrj return _M_invoke(_Indices()); 155*38fd1498Szrj } 156*38fd1498Szrj 157*38fd1498Szrj private: 158*38fd1498Szrj template<std::size_t... _Indices> 159*38fd1498Szrj typename result_of<_Callable(_Args...)>::type _M_invokestd::_Bind_simple160*38fd1498Szrj _M_invoke(_Index_tuple<_Indices...>) 161*38fd1498Szrj { 162*38fd1498Szrj // std::bind always forwards bound arguments as lvalues, 163*38fd1498Szrj // but this type can call functions which only accept rvalues. 164*38fd1498Szrj return std::forward<_Callable>(std::get<0>(_M_bound))( 165*38fd1498Szrj std::forward<_Args>(std::get<_Indices+1>(_M_bound))...); 166*38fd1498Szrj } 167*38fd1498Szrj 168*38fd1498Szrj std::tuple<_Callable, _Args...> _M_bound; 169*38fd1498Szrj }; 170*38fd1498Szrj 171*38fd1498Szrj template<typename _Func, typename... _BoundArgs> 172*38fd1498Szrj struct _Bind_simple_helper 173*38fd1498Szrj { 174*38fd1498Szrj typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type> 175*38fd1498Szrj __maybe_type; 176*38fd1498Szrj typedef typename __maybe_type::type __func_type; 177*38fd1498Szrj typedef _Bind_simple<__func_type(typename decay<_BoundArgs>::type...)> 178*38fd1498Szrj __type; 179*38fd1498Szrj }; 180*38fd1498Szrj 181*38fd1498Szrj // Simplified version of std::bind for internal use, without support for 182*38fd1498Szrj // unbound arguments, placeholders or nested bind expressions. 183*38fd1498Szrj template<typename _Callable, typename... _Args> 184*38fd1498Szrj typename _Bind_simple_helper<_Callable, _Args...>::__type __bind_simple(_Callable && __callable,_Args &&...__args)185*38fd1498Szrj __bind_simple(_Callable&& __callable, _Args&&... __args) 186*38fd1498Szrj { 187*38fd1498Szrj typedef _Bind_simple_helper<_Callable, _Args...> __helper_type; 188*38fd1498Szrj typedef typename __helper_type::__maybe_type __maybe_type; 189*38fd1498Szrj typedef typename __helper_type::__type __result_type; 190*38fd1498Szrj return __result_type( 191*38fd1498Szrj __maybe_type::__do_wrap( std::forward<_Callable>(__callable)), 192*38fd1498Szrj std::forward<_Args>(__args)...); 193*38fd1498Szrj } 194*38fd1498Szrj 195*38fd1498Szrj // Explicit instantiation due to -fno-implicit-instantiation. 196*38fd1498Szrj template void call_once(once_flag&, void (thread::*&&)(), reference_wrapper<thread>&&); 197*38fd1498Szrj template _Bind_simple_helper<void (thread::*)(), reference_wrapper<thread>>::__type __bind_simple(void (thread::*&&)(), reference_wrapper<thread>&&); 198*38fd1498Szrj #endif // _GLIBCXX_HAVE_TLS 199*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 200*38fd1498Szrj } // namespace std 201*38fd1498Szrj #endif // _GLIBCXX_SHARED 202*38fd1498Szrj #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 203