]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/c++11/future.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++11 / future.cc
CommitLineData
c910ceff
JW
1// future -*- C++ -*-
2
99dee823 3// Copyright (C) 2009-2021 Free Software Foundation, Inc.
c910ceff
JW
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>
b333e8eb 26#include <bits/functexcept.h>
c910ceff 27
c910ceff
JW
28namespace
29{
30 struct future_error_category : public std::error_category
31 {
32 virtual const char*
84b63c01 33 name() const noexcept
c910ceff
JW
34 { return "future"; }
35
168ad5f5 36 _GLIBCXX_DEFAULT_ABI_TAG
c910ceff
JW
37 virtual std::string message(int __ec) const
38 {
39 std::string __msg;
40 switch (std::future_errc(__ec))
41 {
42 case std::future_errc::broken_promise:
43 __msg = "Broken promise";
44 break;
45 case std::future_errc::future_already_retrieved:
46 __msg = "Future already retrieved";
47 break;
48 case std::future_errc::promise_already_satisfied:
49 __msg = "Promise already satisfied";
50 break;
a14dd08a
JW
51 case std::future_errc::no_state:
52 __msg = "No associated state";
53 break;
c910ceff
JW
54 default:
55 __msg = "Unknown error";
56 break;
57 }
58 return __msg;
59 }
60 };
61
62 const future_error_category&
84b63c01 63 __future_category_instance() noexcept
c910ceff 64 {
1cbe724c 65 static const future_error_category __fec{};
c910ceff
JW
66 return __fec;
67 }
68}
69
12ffa228
BK
70namespace std _GLIBCXX_VISIBILITY(default)
71{
72_GLIBCXX_BEGIN_NAMESPACE_VERSION
53dc5044 73
b333e8eb
JW
74 void
75 __throw_future_error(int __i __attribute__((unused)))
76 { _GLIBCXX_THROW_OR_ABORT(future_error(make_error_code(future_errc(__i)))); }
77
84b63c01 78 const error_category& future_category() noexcept
94a86be0 79 { return __future_category_instance(); }
8d1b99e2 80
84b63c01 81 future_error::~future_error() noexcept { }
8d1b99e2 82
faa00511 83 const char*
664e99ea 84 future_error::what() const noexcept { return logic_error::what(); }
53dc5044 85
8ba7f29e 86#ifdef _GLIBCXX_HAS_GTHREADS
e9599233
BK
87 __future_base::_Result_base::_Result_base() = default;
88
89 __future_base::_Result_base::~_Result_base() = default;
9db7c931
JW
90
91 void
92 __future_base::_State_baseV2::_Make_ready::_S_run(void* p)
93 {
94 unique_ptr<_Make_ready> mr{static_cast<_Make_ready*>(p)};
95 if (auto state = mr->_M_shared_state.lock())
96 {
eae801ba
TR
97 // Use release MO to synchronize with observers of the ready state.
98 state->_M_status._M_store_notify_all(_Status::__ready,
99 memory_order_release);
9db7c931
JW
100 }
101 }
102
103 // defined in src/c++11/condition_variable.cc
104 extern void
105 __at_thread_exit(__at_thread_exit_elt* elt);
106
107 void
108 __future_base::_State_baseV2::_Make_ready::_M_set()
109 {
110 _M_cb = &_Make_ready::_S_run;
111 __at_thread_exit(this);
112 }
8ba7f29e 113#endif // _GLIBCXX_HAS_GTHREADS
e9599233 114
12ffa228 115_GLIBCXX_END_NAMESPACE_VERSION
e9599233 116} // namespace std