Skip to content

Commit a0437b3

Browse files
committed
replace all tag_invoke customizations of start with membr fns
1 parent 153f4e3 commit a0437b3

26 files changed

+106
-150
lines changed

examples/algorithms/retry.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ struct _op {
101101
}
102102
}
103103

104-
friend void tag_invoke(stdexec::start_t, _op& o) noexcept {
105-
stdexec::start(*o.o_);
104+
void start() & noexcept {
105+
stdexec::start(*o_);
106106
}
107107
};
108108

examples/benchmark/fibonacci.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ struct fib_s {
4949
long n;
5050
Scheduler sched;
5151

52-
friend void tag_invoke(stdexec::start_t, operation& self) noexcept {
53-
if (self.n < self.cutoff) {
54-
stdexec::set_value(static_cast<Receiver&&>(self.rcvr_), serial_fib(self.n));
52+
void start() & noexcept {
53+
if (n < cutoff) {
54+
stdexec::set_value(static_cast<Receiver&&>(rcvr_), serial_fib(n));
5555
} else {
5656
auto mkchild = [&](long n) {
57-
return stdexec::starts_on(self.sched, fib_sender(fib_s{self.cutoff, n, self.sched}));
57+
return stdexec::starts_on(sched, fib_sender(fib_s{cutoff, n, sched}));
5858
};
5959

6060
stdexec::start_detached(
61-
stdexec::when_all(mkchild(self.n - 1), mkchild(self.n - 2))
62-
| stdexec::then([rcvr = static_cast<Receiver&&>(self.rcvr_)](long a, long b) mutable {
61+
stdexec::when_all(mkchild(n - 1), mkchild(n - 2))
62+
| stdexec::then([rcvr = static_cast<Receiver&&>(rcvr_)](long a, long b) mutable {
6363
stdexec::set_value(static_cast<Receiver&&>(rcvr), a + b);
6464
}));
6565
}

examples/benchmark/static_thread_pool_old.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "./common.hpp"
1818
#include "./static_thread_pool_old.hpp"
1919

20+
#include <utility> // IWYU pragma: keep for std::ignore
21+
2022
struct RunThread {
2123
void operator()(
2224
exec_old::static_thread_pool& pool,
@@ -29,7 +31,7 @@ struct RunThread {
2931
std::atomic<bool>& stop,
3032
exec::numa_policy numa) {
3133
int numa_node = numa.thread_index_to_node(tid);
32-
numa.bind_to_node(numa_node);
34+
std::ignore = numa.bind_to_node(numa_node);
3335
auto scheduler = pool.get_scheduler();
3436
std::mutex mut;
3537
std::condition_variable cv;

examples/benchmark/static_thread_pool_old.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace exec_old {
107107
struct bulk_receiver;
108108

109109
template <class CvrefSenderId, class ReceiverId, std::integral Shape, class Fun>
110-
struct bulk_op_state;
110+
class bulk_op_state;
111111

112112
struct transform_bulk {
113113
template <class Data, class Sender>
@@ -430,8 +430,9 @@ namespace exec_old {
430430
pool_.enqueue(op);
431431
}
432432

433-
friend void tag_invoke(stdexec::start_t, operation& op) noexcept {
434-
op.enqueue_(&op);
433+
public:
434+
void start() & noexcept {
435+
enqueue_(this);
435436
}
436437
};
437438

@@ -660,7 +661,7 @@ namespace exec_old {
660661
};
661662

662663
template <class CvrefSenderId, class ReceiverId, std::integral Shape, class Fun>
663-
struct static_thread_pool::bulk_op_state {
664+
class static_thread_pool::bulk_op_state {
664665
using CvrefSender = stdexec::__cvref_t<CvrefSenderId>;
665666
using Receiver = stdexec::__t<ReceiverId>;
666667

@@ -676,13 +677,9 @@ namespace exec_old {
676677
using inner_op_state = stdexec::connect_result_t<CvrefSender, bulk_rcvr>;
677678

678679
shared_state shared_state_;
679-
680680
inner_op_state inner_op_;
681681

682-
friend void tag_invoke(stdexec::start_t, bulk_op_state& op) noexcept {
683-
stdexec::start(op.inner_op_);
684-
}
685-
682+
public:
686683
bulk_op_state(
687684
static_thread_pool& pool,
688685
Shape shape,
@@ -692,6 +689,10 @@ namespace exec_old {
692689
: shared_state_(pool, static_cast<Receiver&&>(receiver), shape, fn)
693690
, inner_op_{stdexec::connect(static_cast<CvrefSender&&>(sender), bulk_rcvr{shared_state_})} {
694691
}
692+
693+
void start() & noexcept {
694+
stdexec::start(inner_op_);
695+
}
695696
};
696697

697698
} // namespace exec_old

examples/nvexec/maxwell/snr.cuh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ namespace nvexec::_strm::repeat_n {
163163
std::size_t n_{};
164164
std::size_t i_{};
165165

166-
friend void tag_invoke(stdexec::start_t, operation_state_t& op) noexcept {
167-
if (op.stream_provider_.status_ != cudaSuccess) {
166+
void start() & noexcept {
167+
if (this->stream_provider_.status_ != cudaSuccess) {
168168
// Couldn't allocate memory for operation state, complete with error
169-
op.propagate_completion_signal(stdexec::set_error, std::move(op.stream_provider_.status_));
169+
this->propagate_completion_signal(stdexec::set_error, std::move(this->stream_provider_.status_));
170170
} else {
171-
if (op.n_) {
172-
stdexec::start(*op.pred_op_state_);
171+
if (n_) {
172+
stdexec::start(*pred_op_state_);
173173
} else {
174-
op.propagate_completion_signal(stdexec::set_value);
174+
this->propagate_completion_signal(stdexec::set_value);
175175
}
176176
}
177177
}
@@ -305,11 +305,11 @@ namespace repeat_n_detail {
305305
std::size_t n_{};
306306
std::size_t i_{};
307307

308-
friend void tag_invoke(stdexec::start_t, operation_state_t& op) noexcept {
309-
if (op.n_) {
310-
stdexec::start(*op.pred_op_state_);
308+
void start() & noexcept {
309+
if (n_) {
310+
stdexec::start(*pred_op_state_);
311311
} else {
312-
stdexec::set_value(std::move(op.rcvr_));
312+
stdexec::set_value(std::move(rcvr_));
313313
}
314314
}
315315

examples/retry.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ struct fail_some {
3131
struct op {
3232
R r_;
3333

34-
friend void tag_invoke(stdexec::start_t, op& self) noexcept {
34+
void start() & noexcept {
3535
static int i = 0;
3636
if (++i < 3) {
3737
std::printf("fail!\n");
38-
stdexec::set_error(std::move(self.r_), std::exception_ptr{});
38+
stdexec::set_error(std::move(r_), std::exception_ptr{});
3939
} else {
4040
std::printf("success!\n");
41-
stdexec::set_value(std::move(self.r_), 42);
41+
stdexec::set_value(std::move(r_), 42);
4242
}
4343
}
4444
};

include/exec/__detail/__system_context_default_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace exec::__system_context_default_impl {
136136
}
137137

138138
//! Starts the operation that will schedule work on the system scheduler.
139-
void start() noexcept {
139+
void start() & noexcept {
140140
stdexec::start(__inner_op_);
141141
}
142142

include/exec/start_now.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace exec {
126126
, __rcvr_(static_cast<_Receiver&&>(__rcvr)) {
127127
}
128128

129-
void start() noexcept {
129+
void start() & noexcept {
130130
const __joiner* expected = &__empty_joiner_;
131131
if (!__stg_->__joiner_.compare_exchange_strong(expected, this)) {
132132
join();

test/exec/async_scope/test_spawn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace {
1919
struct operation {
2020
Receiver rcvr_;
2121

22-
friend void tag_invoke(ex::start_t, operation& self) noexcept {
23-
ex::set_value(std::move(self.rcvr_));
22+
void start() & noexcept {
23+
ex::set_value(std::move(rcvr_));
2424
}
2525
};
2626

test/exec/async_scope/test_spawn_future.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace {
3232
struct operation {
3333
Receiver rcvr_;
3434

35-
friend void tag_invoke(ex::start_t, operation& self) noexcept {
36-
ex::set_value(std::move(self.rcvr_));
35+
void start() & noexcept {
36+
ex::set_value(std::move(rcvr_));
3737
}
3838
};
3939

0 commit comments

Comments
 (0)