Skip to content

Commit d062f2e

Browse files
authored
clean-up on previous std::execution::task commit (#1822)
1 parent ec3fde2 commit d062f2e

File tree

3 files changed

+84
-85
lines changed

3 files changed

+84
-85
lines changed

include/stdexec/__detail/__task.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "__optional.hpp"
2525
#include "__schedulers.hpp"
2626
#include "__task_scheduler.hpp"
27-
#include "__variant.hpp"
2827

2928
#include <cstddef>
3029
#include <exception>
@@ -72,7 +71,7 @@ namespace STDEXEC {
7271
};
7372

7473
struct __any_alloc_base {
75-
virtual void __deallocate(void* __ptr, size_t __bytes) noexcept = 0;
74+
virtual void __deallocate_(void* __ptr, size_t __bytes) noexcept = 0;
7675
};
7776

7877
template <class _PAlloc>
@@ -84,7 +83,7 @@ namespace STDEXEC {
8483
: __alloc_(std::move(__alloc)) {
8584
}
8685

87-
void __deallocate(void* __ptr, size_t __bytes) noexcept final {
86+
void __deallocate_(void* __ptr, size_t __bytes) noexcept final {
8887
// __bytes here is the same as __bytes passed to promise_type::operator new. We
8988
// overallocated to store the allocator in the blocks immediately following the
9089
// promise object. We now use that allocator to deallocate the entire block of
@@ -451,7 +450,7 @@ namespace STDEXEC {
451450
size_t const __promise_blocks = __task::__divmod(__bytes, sizeof(__task::__memblock));
452451
void* const __alloc_loc = static_cast<__task::__memblock*>(__ptr) + __promise_blocks;
453452
auto* __alloc = static_cast<__task::__any_alloc_base*>(__alloc_loc);
454-
__alloc->__deallocate(__ptr, __bytes);
453+
__alloc->__deallocate_(__ptr, __bytes);
455454
}
456455

457456
private:

include/stdexec/execution.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "__detail/__stopped_as_optional.hpp"
5757
#include "__detail/__submit.hpp"
5858
#include "__detail/__sync_wait.hpp"
59+
#include "__detail/__task.hpp"
5960
#include "__detail/__task_scheduler.hpp"
6061
#include "__detail/__then.hpp"
6162
#include "__detail/__transfer_just.hpp"

test/exec/test_task.cpp

Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
# include <string>
3030

31-
using namespace exec;
32-
using namespace STDEXEC;
31+
namespace ex = STDEXEC;
3332
using namespace std::string_literals;
3433

3534
namespace {
@@ -45,29 +44,29 @@ namespace {
4544
}
4645

4746
auto test_stickiness_for_two_single_thread_contexts_nested(
48-
scheduler auto scheduler1,
49-
scheduler auto,
47+
ex::scheduler auto scheduler1,
48+
ex::scheduler auto,
5049
auto id1,
51-
auto id2) -> task<void> {
50+
auto id2) -> exec::task<void> {
5251
CHECK(get_id() == id2); // This task is started in context2
53-
co_await schedule(scheduler1); // Try to schedule in context1
52+
co_await ex::schedule(scheduler1); // Try to ex::schedule in context1
5453
CHECK(get_id() == id2); // But this task is still in context2
55-
co_await reschedule_coroutine_on(scheduler1); // Transition to context1
54+
co_await exec::reschedule_coroutine_on(scheduler1); // Transition to context1
5655
CHECK(get_id() == id1); // Now we are in context1
5756
} // Reschedules back to context2
5857

5958
auto test_stickiness_for_two_single_thread_contexts_(
6059
auto scheduler1,
6160
auto scheduler2,
6261
auto id1,
63-
auto id2) -> task<void> {
62+
auto id2) -> exec::task<void> {
6463
CHECK(get_id() == id1); // This task is start in context1
65-
co_await schedule(scheduler2); // Try to schedule in context2
64+
co_await ex::schedule(scheduler2); // Try to ex::schedule in context2
6665
CHECK(get_id() == id1); // But this task is still in context1
67-
co_await (schedule(scheduler1) | then([&] { CHECK(get_id() == id1); }));
68-
co_await (schedule(scheduler2) | then([&] { CHECK(get_id() == id2); }));
66+
co_await (ex::schedule(scheduler1) | ex::then([&] { CHECK(get_id() == id1); }));
67+
co_await (ex::schedule(scheduler2) | ex::then([&] { CHECK(get_id() == id2); }));
6968
CHECK(get_id() == id1);
70-
co_await reschedule_coroutine_on(scheduler2); // Transition to context2
69+
co_await exec::reschedule_coroutine_on(scheduler2); // Transition to context2
7170
CHECK(get_id() == id2); // Now we are in context2
7271
// Child task inherits context2
7372
co_await test_stickiness_for_two_single_thread_contexts_nested(
@@ -79,21 +78,21 @@ namespace {
7978
auto scheduler1,
8079
auto scheduler2,
8180
auto id1,
82-
auto id2) -> task<void> {
83-
co_await reschedule_coroutine_on(scheduler2); // Transition to context2
81+
auto id2) -> exec::task<void> {
82+
co_await exec::reschedule_coroutine_on(scheduler2); // Transition to context2
8483
CHECK(get_id() == id2); // Now we are in context2
8584
// Child task inherits context2
8685
co_await (
8786
test_stickiness_for_two_single_thread_contexts_nested(scheduler1, scheduler2, id1, id2)
88-
| then([&] { CHECK(get_id() == id2); }));
87+
| ex::then([&] { CHECK(get_id() == id2); }));
8988
}
9089

9190
auto test_stickiness_for_two_single_thread_contexts(
9291
auto scheduler1,
9392
auto scheduler2,
9493
auto id1,
95-
auto id2) -> task<void> {
96-
co_await reschedule_coroutine_on(scheduler1);
94+
auto id2) -> exec::task<void> {
95+
co_await exec::reschedule_coroutine_on(scheduler1);
9796
CHECK(get_id() == id1);
9897
co_await test_stickiness_for_two_single_thread_contexts_(scheduler1, scheduler2, id1, id2);
9998
CHECK(get_id() == id1);
@@ -103,129 +102,129 @@ namespace {
103102
auto scheduler1,
104103
auto scheduler2,
105104
auto id1,
106-
auto id2) -> task<void> {
107-
co_await reschedule_coroutine_on(scheduler1);
105+
auto id2) -> exec::task<void> {
106+
co_await exec::reschedule_coroutine_on(scheduler1);
108107
CHECK(get_id() == id1);
109108
co_await test_stickiness_for_two_single_thread_contexts_with_sender_(
110109
scheduler1, scheduler2, id1, id2);
111110
CHECK(get_id() == id1);
112111
}
113112

114113
TEST_CASE("Test stickiness with two single threads", "[types][sticky][task]") {
115-
single_thread_context context1;
116-
single_thread_context context2;
117-
scheduler auto scheduler1 = context1.get_scheduler();
118-
scheduler auto scheduler2 = context2.get_scheduler();
119-
sync_wait(when_all(
120-
schedule(scheduler1) | then([] { thread_id = 1; }),
121-
schedule(scheduler2) | then([] { thread_id = 2; })));
114+
exec::single_thread_context context1;
115+
exec::single_thread_context context2;
116+
ex::scheduler auto scheduler1 = context1.get_scheduler();
117+
ex::scheduler auto scheduler2 = context2.get_scheduler();
118+
ex::sync_wait(ex::when_all(
119+
ex::schedule(scheduler1) | ex::then([] { thread_id = 1; }),
120+
ex::schedule(scheduler2) | ex::then([] { thread_id = 2; })));
122121
auto id1 = 1;
123122
auto id2 = 2;
124123
auto t = test_stickiness_for_two_single_thread_contexts(scheduler1, scheduler2, id1, id2);
125-
sync_wait(std::move(t));
124+
ex::sync_wait(std::move(t));
126125
}
127126

128127
TEST_CASE("Test stickiness with two single threads with on", "[types][sticky][task]") {
129-
single_thread_context context1;
130-
single_thread_context context2;
131-
scheduler auto scheduler1 = context1.get_scheduler();
132-
scheduler auto scheduler2 = context2.get_scheduler();
133-
sync_wait(when_all(
134-
schedule(scheduler1) | then([] { thread_id = 1; }),
135-
schedule(scheduler2) | then([] { thread_id = 2; })));
128+
exec::single_thread_context context1;
129+
exec::single_thread_context context2;
130+
ex::scheduler auto scheduler1 = context1.get_scheduler();
131+
ex::scheduler auto scheduler2 = context2.get_scheduler();
132+
ex::sync_wait(ex::when_all(
133+
ex::schedule(scheduler1) | ex::then([] { thread_id = 1; }),
134+
ex::schedule(scheduler2) | ex::then([] { thread_id = 2; })));
136135
auto id1 = 1;
137136
auto id2 = 2;
138-
auto t = starts_on(
137+
auto t = ex::starts_on(
139138
scheduler1,
140139
test_stickiness_for_two_single_thread_contexts_(scheduler1, scheduler2, id1, id2));
141-
sync_wait(std::move(t) | then([&] { CHECK(get_id() == id1); }));
140+
ex::sync_wait(std::move(t) | ex::then([&] { CHECK(get_id() == id1); }));
142141
}
143142

144143
TEST_CASE("Test stickiness with two single threads with sender", "[types][sticky][task]") {
145-
single_thread_context context1;
146-
single_thread_context context2;
147-
scheduler auto scheduler1 = context1.get_scheduler();
148-
scheduler auto scheduler2 = context2.get_scheduler();
149-
sync_wait(when_all(
150-
schedule(scheduler1) | then([] { thread_id = 1; }),
151-
schedule(scheduler2) | then([] { thread_id = 2; })));
144+
exec::single_thread_context context1;
145+
exec::single_thread_context context2;
146+
ex::scheduler auto scheduler1 = context1.get_scheduler();
147+
ex::scheduler auto scheduler2 = context2.get_scheduler();
148+
ex::sync_wait(ex::when_all(
149+
ex::schedule(scheduler1) | ex::then([] { thread_id = 1; }),
150+
ex::schedule(scheduler2) | ex::then([] { thread_id = 2; })));
152151
auto id1 = 1;
153152
auto id2 = 2;
154153
auto t =
155154
test_stickiness_for_two_single_thread_contexts_with_sender(scheduler1, scheduler2, id1, id2);
156-
sync_wait(std::move(t));
155+
ex::sync_wait(std::move(t));
157156
}
158157

159158
TEST_CASE(
160159
"Test stickiness with two single threads with sender with starts_on",
161160
"[types][sticky][task]") {
162-
single_thread_context context1;
163-
single_thread_context context2;
164-
scheduler auto scheduler1 = context1.get_scheduler();
165-
scheduler auto scheduler2 = context2.get_scheduler();
166-
sync_wait(when_all(
167-
schedule(scheduler1) | then([] { thread_id = 1; }),
168-
schedule(scheduler2) | then([] { thread_id = 2; })));
161+
exec::single_thread_context context1;
162+
exec::single_thread_context context2;
163+
ex::scheduler auto scheduler1 = context1.get_scheduler();
164+
ex::scheduler auto scheduler2 = context2.get_scheduler();
165+
ex::sync_wait(ex::when_all(
166+
ex::schedule(scheduler1) | ex::then([] { thread_id = 1; }),
167+
ex::schedule(scheduler2) | ex::then([] { thread_id = 2; })));
169168
auto id1 = 1;
170169
auto id2 = 2;
171-
auto t = starts_on(
170+
auto t = ex::starts_on(
172171
scheduler1,
173172
test_stickiness_for_two_single_thread_contexts_with_sender_(
174173
scheduler1, scheduler2, id1, id2));
175-
sync_wait(std::move(t) | then([&] { CHECK(get_id() == id1); }));
174+
ex::sync_wait(std::move(t) | ex::then([&] { CHECK(get_id() == id1); }));
176175
}
177176

178177
TEST_CASE("Use two inline schedulers", "[types][sticky][task]") {
179-
scheduler auto scheduler1 = STDEXEC::inline_scheduler{};
180-
scheduler auto scheduler2 = STDEXEC::inline_scheduler{};
181-
sync_wait(when_all(
182-
schedule(scheduler1) | then([] { thread_id = 0; }),
183-
schedule(scheduler2) | then([] { thread_id = 0; })));
178+
ex::scheduler auto scheduler1 = STDEXEC::inline_scheduler{};
179+
ex::scheduler auto scheduler2 = STDEXEC::inline_scheduler{};
180+
ex::sync_wait(ex::when_all(
181+
ex::schedule(scheduler1) | ex::then([] { thread_id = 0; }),
182+
ex::schedule(scheduler2) | ex::then([] { thread_id = 0; })));
184183
auto id1 = 0;
185184
auto id2 = 0;
186185
auto t = test_stickiness_for_two_single_thread_contexts(scheduler1, scheduler2, id1, id2);
187-
sync_wait(std::move(t));
186+
ex::sync_wait(std::move(t));
188187
}
189188

190189
auto test_stick_on_main_nested(
191-
scheduler auto sched1,
192-
scheduler auto,
190+
ex::scheduler auto sched1,
191+
ex::scheduler auto,
193192
auto id_main_thread,
194193
[[maybe_unused]] auto id1,
195-
[[maybe_unused]] auto id2) -> task<void> {
194+
[[maybe_unused]] auto id2) -> exec::task<void> {
196195
CHECK(get_id() == id_main_thread);
197-
co_await schedule(sched1);
196+
co_await ex::schedule(sched1);
198197
CHECK(get_id() == id_main_thread);
199198
}
200199

201200
auto test_stick_on_main(
202-
scheduler auto sched1,
203-
scheduler auto sched2,
201+
ex::scheduler auto sched1,
202+
ex::scheduler auto sched2,
204203
auto id_main_thread,
205204
[[maybe_unused]] auto id1,
206-
[[maybe_unused]] auto id2) -> task<void> {
205+
[[maybe_unused]] auto id2) -> exec::task<void> {
207206
CHECK(get_id() == id_main_thread);
208-
co_await schedule(sched1);
207+
co_await ex::schedule(sched1);
209208
CHECK(get_id() == id_main_thread);
210-
co_await schedule(sched2);
209+
co_await ex::schedule(sched2);
211210
CHECK(get_id() == id_main_thread);
212211
co_await test_stick_on_main_nested(sched1, sched2, id_main_thread, id1, id2);
213212
CHECK(get_id() == id_main_thread);
214213
}
215214

216215
TEST_CASE("Stick on main thread if completes_inline is not used", "[types][sticky][task]") {
217-
single_thread_context context1;
218-
single_thread_context context2;
219-
scheduler auto scheduler1 = context1.get_scheduler();
220-
scheduler auto scheduler2 = context2.get_scheduler();
221-
sync_wait(when_all(
222-
schedule(scheduler1) | then([] { thread_id = 1; }),
223-
schedule(scheduler2) | then([] { thread_id = 2; })));
216+
exec::single_thread_context context1;
217+
exec::single_thread_context context2;
218+
ex::scheduler auto scheduler1 = context1.get_scheduler();
219+
ex::scheduler auto scheduler2 = context2.get_scheduler();
220+
ex::sync_wait(ex::when_all(
221+
ex::schedule(scheduler1) | ex::then([] { thread_id = 1; }),
222+
ex::schedule(scheduler2) | ex::then([] { thread_id = 2; })));
224223
auto id1 = 1;
225224
auto id2 = 2;
226225
auto id_main_thread = 0;
227226
auto t = test_stick_on_main(scheduler1, scheduler2, id_main_thread, id1, id2);
228-
sync_wait(std::move(t));
227+
ex::sync_wait(std::move(t));
229228
}
230229

231230
auto check_stop_possible() -> exec::task<void> {
@@ -234,7 +233,7 @@ namespace {
234233
}
235234

236235
TEST_CASE("task - stop token is forwarded", "[types][task]") {
237-
single_thread_context context{};
236+
exec::single_thread_context context{};
238237
exec::async_scope scope;
239238
scope.spawn(STDEXEC::starts_on(context.get_scheduler(), check_stop_possible()));
240239
CHECK(STDEXEC::sync_wait(scope.on_empty()));
@@ -270,9 +269,9 @@ namespace {
270269
}
271270

272271
struct test_domain {
273-
template <sender_expr_for<then_t> _Sender>
272+
template <ex::sender_expr_for<ex::then_t> _Sender>
274273
static constexpr auto transform_sender(STDEXEC::set_value_t, _Sender&&, auto&&...) noexcept {
275-
return just("goodbye"s);
274+
return ex::just("goodbye"s);
276275
}
277276
};
278277

@@ -286,7 +285,7 @@ namespace {
286285
template <class, class>
287286
using awaiter_context_t = test_task_context;
288287

289-
static constexpr auto query(get_scheduler_t) noexcept {
288+
static constexpr auto query(ex::get_scheduler_t) noexcept {
290289
return basic_inline_scheduler<test_domain>{};
291290
}
292291
};
@@ -296,7 +295,7 @@ namespace {
296295

297296
TEST_CASE("task - can co_await a sender adaptor closure object", "[types][task]") {
298297
auto salutation = []() -> test_task<std::string> {
299-
co_return co_await then([] { return "hello"s; });
298+
co_return co_await ex::then([] { return "hello"s; });
300299
}();
301300
auto [msg] = STDEXEC::sync_wait(std::move(salutation)).value();
302301
CHECK(msg == "goodbye"s);

0 commit comments

Comments
 (0)