source: mainline/uspace/lib/cpp/include/__bits/thread/future.hpp@ c735afb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c735afb was b57a3ee, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: refactored the library layout, everything from the impl directory was moved to the bits directory for the sake of consistency, updated copyright notices and include guards

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2018 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 <memory>
33#include <system_error>
34#include <type_traits>
35
36namespace std
37{
38 /**
39 * 30.6, futures:
40 */
41
42 enum class future_errc
43 { // The 5001 start is to not collide with system_error's codes.
44 broken_promise = 5001,
45 future_already_retrieved,
46 promise_already_satisfied,
47 no_state
48 };
49
50 enum class launch
51 {
52 async,
53 deferred
54 };
55
56 enum class future_status
57 {
58 ready,
59 timeout,
60 deferred
61 };
62
63 /**
64 * 30.6.2, error handling:
65 */
66
67 template<>
68 struct is_error_code_enum<future_errc>: true_type
69 { /* DUMMY BODY */ };
70
71 error_code make_error_code(future_errc) noexcept;
72 error_condition make_error_condition(future_errc) noexcept;
73
74 const error_category& future_category() noexcept;
75
76 /**
77 * 30.6.3, class future_error:
78 */
79
80 class future_error: public logic_error
81 {
82 public:
83 future_error(error_code ec);
84
85 const error_code& code() const noexcept;
86
87 private:
88 error_code code_;
89 };
90
91 /**
92 * 30.6.4, shared state:
93 */
94
95 template<class R>
96 class promise
97 {
98 };
99
100 template<class R>
101 class promise<R&>
102 {
103 };
104
105 template<>
106 class promise<void>
107 {
108 };
109
110 template<class R>
111 void swap(promise<R>& lhs, promise<R>& rhs) noexcept
112 {
113 lhs.swap(rhs);
114 }
115
116 template<class R, class Alloc>
117 struct uses_allocator<promise<R>, Alloc>: true_type
118 { /* DUMMY BODY */ };
119
120 template<class R>
121 class future
122 {
123 };
124
125 template<class R>
126 class future<R&>
127 {
128 };
129
130 template<>
131 class future<void>
132 {
133 };
134
135 template<class R>
136 class shared_future
137 {
138 };
139
140 template<class R>
141 class shared_future<R&>
142 {
143 };
144
145 template<>
146 class shared_future<void>
147 {
148 };
149
150 template<class>
151 class packaged_task; // undefined
152
153 template<class R, class... Args>
154 class packaged_task<R(Args...)>
155 {
156 };
157
158 template<class R, class... Args>
159 void swap(packaged_task<R(Args...)>& lhs, packaged_task<R(Args...)>& rhs) noexcept
160 {
161 lhs.swap(rhs);
162 };
163
164 template<class R, class Alloc>
165 struct uses_allocator<packaged_task<R>, Alloc>: true_type
166 { /* DUMMY BODY */ };
167
168 template<class F, class... Args>
169 future<result_of_t<decay_t<F>(decay_t<Args>...)>>
170 async(F&& f, Args&&... args)
171 {
172 // TODO: implement
173 }
174
175 template<class F, class... Args>
176 future<result_of_t<decay_t<F>(decay_t<Args>...)>>
177 async(launch, F&& f, Args&&... args)
178 {
179 // TODO: implement
180 }
181}
182
183#endif
Note: See TracBrowser for help on using the repository browser.