OSDN Git Service

PR libstdc++/52128
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / c++11 / future.cc
1 // future -*- C++ -*-
2
3 // Copyright (C) 2009, 2010, 2011, 2012 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 <future>
26
27 namespace
28 {
29   struct future_error_category : public std::error_category
30   {
31     virtual const char*
32     name() const noexcept
33     { return "future"; }
34
35     virtual std::string message(int __ec) const
36     {
37       std::string __msg;
38       switch (std::future_errc(__ec))
39       {
40       case std::future_errc::broken_promise:
41           __msg = "Broken promise";
42           break;
43       case std::future_errc::future_already_retrieved:
44           __msg = "Future already retrieved";
45           break;
46       case std::future_errc::promise_already_satisfied:
47           __msg = "Promise already satisfied";
48           break;
49       case std::future_errc::no_state:
50           __msg = "No associated state";
51           break;
52       default:
53           __msg = "Unknown error";
54           break;
55       }
56       return __msg;
57     }
58   };
59
60   const future_error_category&
61   __future_category_instance() noexcept
62   {
63     static const future_error_category __fec;
64     return __fec;
65   }
66 }
67
68 namespace std _GLIBCXX_VISIBILITY(default)
69 {
70 _GLIBCXX_BEGIN_NAMESPACE_VERSION
71
72   const error_category& future_category() noexcept
73   { return __future_category_instance(); }
74
75   future_error::~future_error() noexcept { }
76
77   const char*
78   future_error::what() const noexcept { return _M_code.message().c_str(); }
79
80 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
81   && (ATOMIC_INT_LOCK_FREE > 1)
82   __future_base::_Result_base::_Result_base() = default;
83
84   __future_base::_Result_base::~_Result_base() = default;
85
86   __future_base::_State_base::~_State_base() = default;
87
88 #ifdef _GLIBCXX_HAVE_TLS
89   __future_base::_Async_state_common::~_Async_state_common() { _M_join(); }
90
91   // Explicit instantiation due to -fno-implicit-instantiation.
92   template void call_once(once_flag&, void (thread::*&&)(), reference_wrapper<thread>&&);
93   template _Bind_simple_helper<void (thread::*)(), reference_wrapper<thread>>::__type __bind_simple(void (thread::*&&)(), reference_wrapper<thread>&&);
94 #endif
95 #endif
96
97 _GLIBCXX_END_NAMESPACE_VERSION
98 } // namespace std
99
100 // XXX GLIBCXX_ABI Deprecated
101 // gcc-4.6.0
102 // <future> export changes
103 #if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
104     && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
105     && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
106
107 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
108 {
109   const std::error_category* future_category = &__future_category_instance();
110 }
111
112 #define _GLIBCXX_ASM_SYMVER(cur, old, version) \
113    asm (".symver " #cur "," #old "@@@" #version);
114
115 _GLIBCXX_ASM_SYMVER(_ZN9__gnu_cxx15future_categoryE, _ZSt15future_category, GLIBCXX_3.4.14)
116
117 #endif
118