1 | /*
|
---|
2 | * Copyright (c) 2019 Jaroslav Jindrak
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef LIBCPP_BITS_THREAD_FUTURE
|
---|
30 | #define LIBCPP_BITS_THREAD_FUTURE
|
---|
31 |
|
---|
32 | #include <cassert>
|
---|
33 | #include <memory>
|
---|
34 | #include <system_error>
|
---|
35 | #include <type_traits>
|
---|
36 |
|
---|
37 | namespace std
|
---|
38 | {
|
---|
39 | /**
|
---|
40 | * 30.6, futures:
|
---|
41 | */
|
---|
42 |
|
---|
43 | enum class future_errc
|
---|
44 | { // The 5001 start is to not collide with system_error's codes.
|
---|
45 | broken_promise = 5001,
|
---|
46 | future_already_retrieved,
|
---|
47 | promise_already_satisfied,
|
---|
48 | no_state
|
---|
49 | };
|
---|
50 |
|
---|
51 | enum class launch
|
---|
52 | {
|
---|
53 | async,
|
---|
54 | deferred
|
---|
55 | };
|
---|
56 |
|
---|
57 | enum class future_status
|
---|
58 | {
|
---|
59 | ready,
|
---|
60 | timeout,
|
---|
61 | deferred
|
---|
62 | };
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * 30.6.2, error handling:
|
---|
66 | */
|
---|
67 |
|
---|
68 | template<>
|
---|
69 | struct is_error_code_enum<future_errc>: true_type
|
---|
70 | { /* DUMMY BODY */ };
|
---|
71 |
|
---|
72 | error_code make_error_code(future_errc) noexcept;
|
---|
73 | error_condition make_error_condition(future_errc) noexcept;
|
---|
74 |
|
---|
75 | const error_category& future_category() noexcept;
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * 30.6.3, class future_error:
|
---|
79 | */
|
---|
80 |
|
---|
81 | class future_error: public logic_error
|
---|
82 | {
|
---|
83 | public:
|
---|
84 | future_error(error_code ec);
|
---|
85 |
|
---|
86 | const error_code& code() const noexcept;
|
---|
87 |
|
---|
88 | private:
|
---|
89 | error_code code_;
|
---|
90 | };
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * 30.6.4, shared state:
|
---|
94 | */
|
---|
95 |
|
---|
96 | template<class R>
|
---|
97 | class promise
|
---|
98 | {
|
---|
99 | };
|
---|
100 |
|
---|
101 | template<class R>
|
---|
102 | class promise<R&>
|
---|
103 | {
|
---|
104 | };
|
---|
105 |
|
---|
106 | template<>
|
---|
107 | class promise<void>
|
---|
108 | {
|
---|
109 | };
|
---|
110 |
|
---|
111 | template<class R>
|
---|
112 | void swap(promise<R>& lhs, promise<R>& rhs) noexcept
|
---|
113 | {
|
---|
114 | lhs.swap(rhs);
|
---|
115 | }
|
---|
116 |
|
---|
117 | template<class R, class Alloc>
|
---|
118 | struct uses_allocator<promise<R>, Alloc>: true_type
|
---|
119 | { /* DUMMY BODY */ };
|
---|
120 |
|
---|
121 | template<class R>
|
---|
122 | class future
|
---|
123 | {
|
---|
124 | };
|
---|
125 |
|
---|
126 | template<class R>
|
---|
127 | class future<R&>
|
---|
128 | {
|
---|
129 | };
|
---|
130 |
|
---|
131 | template<>
|
---|
132 | class future<void>
|
---|
133 | {
|
---|
134 | };
|
---|
135 |
|
---|
136 | template<class R>
|
---|
137 | class shared_future
|
---|
138 | {
|
---|
139 | };
|
---|
140 |
|
---|
141 | template<class R>
|
---|
142 | class shared_future<R&>
|
---|
143 | {
|
---|
144 | };
|
---|
145 |
|
---|
146 | template<>
|
---|
147 | class shared_future<void>
|
---|
148 | {
|
---|
149 | };
|
---|
150 |
|
---|
151 | template<class>
|
---|
152 | class packaged_task; // undefined
|
---|
153 |
|
---|
154 | template<class R, class... Args>
|
---|
155 | class packaged_task<R(Args...)>
|
---|
156 | {
|
---|
157 | };
|
---|
158 |
|
---|
159 | template<class R, class... Args>
|
---|
160 | void swap(packaged_task<R(Args...)>& lhs, packaged_task<R(Args...)>& rhs) noexcept
|
---|
161 | {
|
---|
162 | lhs.swap(rhs);
|
---|
163 | };
|
---|
164 |
|
---|
165 | template<class R, class Alloc>
|
---|
166 | struct uses_allocator<packaged_task<R>, Alloc>: true_type
|
---|
167 | { /* DUMMY BODY */ };
|
---|
168 |
|
---|
169 | template<class F, class... Args>
|
---|
170 | future<result_of_t<decay_t<F>(decay_t<Args>...)>>
|
---|
171 | async(F&& f, Args&&... args)
|
---|
172 | {
|
---|
173 | // TODO: implement
|
---|
174 | __unimplemented();
|
---|
175 | }
|
---|
176 |
|
---|
177 | template<class F, class... Args>
|
---|
178 | future<result_of_t<decay_t<F>(decay_t<Args>...)>>
|
---|
179 | async(launch, F&& f, Args&&... args)
|
---|
180 | {
|
---|
181 | // TODO: implement
|
---|
182 | __unimplemented();
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | #endif
|
---|