Skip to content

Commit 630c20a

Browse files
committed
various fixes
1 parent da08ace commit 630c20a

File tree

7 files changed

+126
-124
lines changed

7 files changed

+126
-124
lines changed

include/beman/execution/detail/as_tuple.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@
99
// ----------------------------------------------------------------------------
1010

1111
namespace beman::execution::detail {
12+
/*!
13+
* \brief Turn a completion signatures into a std::tuple type.
14+
* \internal
15+
*/
1216
template <typename T>
1317
struct as_tuple;
18+
/*!
19+
* \brief The actual operational partial specialization of as_tuple.
20+
* \internal
21+
*/
1422
template <typename Rc, typename... A>
1523
struct as_tuple<Rc(A...)> {
1624
using type = ::beman::execution::detail::decayed_tuple<Rc, A...>;

include/beman/execution/detail/associate.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ struct impls_for<associate_t> : ::beman::execution::detail::default_impls {
106106
struct op_state {
107107
using sop_t = op_t;
108108
using sscope_token = scope_token;
109+
struct assoc_t {
110+
sscope_token tok;
111+
sop_t op;
112+
};
113+
109114
bool associated{false};
110115
union {
111116
Receiver* rcvr;
112-
struct {
113-
sscope_token tok;
114-
sop_t op;
115-
} assoc;
117+
assoc_t assoc;
116118
};
117119
explicit op_state(Receiver& r) noexcept : rcvr(::std::addressof(r)) {}
118120
explicit op_state(sscope_token tk, wrap_sender&& sndr, Receiver& r) try

include/beman/execution/detail/counting_scope_base.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// ----------------------------------------------------------------------------
1414

1515
namespace beman::execution::detail {
16-
struct counting_scope_base;
16+
class counting_scope_base;
1717
}
1818

1919
// ----------------------------------------------------------------------------
@@ -71,7 +71,7 @@ class beman::execution::detail::counting_scope_base : ::beman::execution::detail
7171

7272
// ----------------------------------------------------------------------------
7373

74-
beman::execution::detail::counting_scope_base::~counting_scope_base() {
74+
inline beman::execution::detail::counting_scope_base::~counting_scope_base() {
7575
::std::lock_guard kerberos(this->mutex);
7676
switch (this->state) {
7777
default:
@@ -83,7 +83,7 @@ beman::execution::detail::counting_scope_base::~counting_scope_base() {
8383
}
8484
}
8585

86-
auto beman::execution::detail::counting_scope_base::close() noexcept -> void {
86+
inline auto beman::execution::detail::counting_scope_base::close() noexcept -> void {
8787
switch (this->state) {
8888
default:
8989
break;
@@ -99,12 +99,12 @@ auto beman::execution::detail::counting_scope_base::close() noexcept -> void {
9999
}
100100
}
101101

102-
auto beman::execution::detail::counting_scope_base::add_node(node* n, ::std::lock_guard<::std::mutex>&) noexcept
102+
inline auto beman::execution::detail::counting_scope_base::add_node(node* n, ::std::lock_guard<::std::mutex>&) noexcept
103103
-> void {
104104
n->next = std::exchange(this->head, n);
105105
}
106106

107-
auto beman::execution::detail::counting_scope_base::try_associate() noexcept -> bool {
107+
inline auto beman::execution::detail::counting_scope_base::try_associate() noexcept -> bool {
108108
::std::lock_guard lock(this->mutex);
109109
switch (this->state) {
110110
default:
@@ -118,7 +118,8 @@ auto beman::execution::detail::counting_scope_base::try_associate() noexcept ->
118118
return true;
119119
}
120120
}
121-
auto beman::execution::detail::counting_scope_base::disassociate() noexcept -> void {
121+
122+
inline auto beman::execution::detail::counting_scope_base::disassociate() noexcept -> void {
122123
{
123124
::std::lock_guard lock(this->mutex);
124125
if (0u < --this->count)
@@ -128,7 +129,7 @@ auto beman::execution::detail::counting_scope_base::disassociate() noexcept -> v
128129
this->complete();
129130
}
130131

131-
auto beman::execution::detail::counting_scope_base::complete() noexcept -> void {
132+
inline auto beman::execution::detail::counting_scope_base::complete() noexcept -> void {
132133
node* current{[this] {
133134
::std::lock_guard lock(this->mutex);
134135
return ::std::exchange(this->head, nullptr);
@@ -138,7 +139,7 @@ auto beman::execution::detail::counting_scope_base::complete() noexcept -> void
138139
}
139140
}
140141

141-
auto beman::execution::detail::counting_scope_base::start_node(node* n) -> void {
142+
inline auto beman::execution::detail::counting_scope_base::start_node(node* n) -> void {
142143
::std::lock_guard kerberos(this->mutex);
143144
switch (this->state) {
144145
case ::beman::execution::detail::counting_scope_base::state_t::unused:

include/beman/execution/detail/schedule_from.hpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,37 @@
44
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_SCHEDULE_FROM
55
#define INCLUDED_BEMAN_EXECUTION_DETAIL_SCHEDULE_FROM
66

7+
#include <beman/execution/detail/as_tuple.hpp>
78
#include <beman/execution/detail/child_type.hpp>
8-
#include <beman/execution/detail/meta_combine.hpp>
99
#include <beman/execution/detail/completion_signatures_of_t.hpp>
1010
#include <beman/execution/detail/connect.hpp>
1111
#include <beman/execution/detail/decayed_tuple.hpp>
1212
#include <beman/execution/detail/default_domain.hpp>
1313
#include <beman/execution/detail/default_impls.hpp>
14-
#include <beman/execution/detail/error_types_of_t.hpp>
1514
#include <beman/execution/detail/env_of_t.hpp>
15+
#include <beman/execution/detail/error_types_of_t.hpp>
1616
#include <beman/execution/detail/fwd_env.hpp>
1717
#include <beman/execution/detail/get_domain.hpp>
1818
#include <beman/execution/detail/get_env.hpp>
1919
#include <beman/execution/detail/impls_for.hpp>
2020
#include <beman/execution/detail/join_env.hpp>
2121
#include <beman/execution/detail/make_sender.hpp>
22+
#include <beman/execution/detail/meta_combine.hpp>
2223
#include <beman/execution/detail/meta_prepend.hpp>
2324
#include <beman/execution/detail/meta_to.hpp>
2425
#include <beman/execution/detail/meta_transform.hpp>
26+
#include <beman/execution/detail/meta_unique.hpp>
2527
#include <beman/execution/detail/query_with_default.hpp>
2628
#include <beman/execution/detail/sched_attrs.hpp>
27-
#include <beman/execution/detail/schedule.hpp>
2829
#include <beman/execution/detail/schedule_result_t.hpp>
30+
#include <beman/execution/detail/schedule.hpp>
2931
#include <beman/execution/detail/scheduler.hpp>
30-
#include <beman/execution/detail/sender.hpp>
3132
#include <beman/execution/detail/sender_in.hpp>
33+
#include <beman/execution/detail/sender.hpp>
3234
#include <beman/execution/detail/set_error.hpp>
3335
#include <beman/execution/detail/set_stopped.hpp>
3436
#include <beman/execution/detail/start.hpp>
3537
#include <beman/execution/detail/transform_sender.hpp>
36-
#include <beman/execution/detail/meta_unique.hpp>
3738

3839
#include <exception>
3940
#include <type_traits>
@@ -43,23 +44,6 @@
4344
// ----------------------------------------------------------------------------
4445

4546
namespace beman::execution::detail {
46-
/*!
47-
* \brief Turn a completion signatures into a std::tuple type.
48-
* \internal
49-
*/
50-
template <typename>
51-
struct as_tuple;
52-
/*!
53-
* \brief The actual operational partial specialization of as_tuple.
54-
* \internal
55-
*/
56-
template <typename Tag, typename... T>
57-
struct as_tuple<Tag(T...)> {
58-
using type = ::beman::execution::detail::decayed_tuple<Tag, T...>;
59-
};
60-
template <typename T>
61-
using as_tuple_t = typename as_tuple<T>::type;
62-
6347
struct schedule_from_t {
6448
template <::beman::execution::scheduler Scheduler, ::beman::execution::sender Sender>
6549
auto operator()(Scheduler&& scheduler, Sender&& sender) const {

include/beman/execution/detail/sender_decompose.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ auto get_sender_data(Sender&& sender) {
4242
//-dk:TODO should use a dynamic/language approach:
4343
auto&& [tag, data, ... children] = sender;
4444
return sender_meta<decltype(tag), decltype(data), ::std::tuple<decltype(children)...>>;
45-
#endif
45+
#else
4646
using sender_type = ::std::remove_cvref_t<Sender>;
4747
static constexpr ::beman::execution::detail::sender_convert_to_any_t at{};
4848

@@ -68,10 +68,11 @@ auto get_sender_data(Sender&& sender) {
6868
return ::beman::execution::detail::sender_data{tag, data, ::std::tie(c0)};
6969
} else if constexpr (requires { sender_type{at, at}; }) {
7070
auto&& [tag, data] = sender;
71-
return ::beman::execution::detail::sender_data{tag, data, ::std::tuple<>()};
71+
return ::beman::execution::detail::sender_data{tag, data, ::std::tuple<>{}};
7272
} else {
7373
return ::beman::execution::detail::sender_meta<void, void, void>{};
7474
}
75+
#endif
7576
}
7677

7778
template <typename Sender>

include/beman/execution/detail/stop_when.hpp

Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -29,105 +29,104 @@ namespace beman::execution::detail {
2929
inline constexpr struct stop_when_t {
3030

3131
template <::beman::execution::sender Sndr, ::beman::execution::stoppable_token Tok>
32-
struct sender {
33-
using sender_concept = ::beman::execution::sender_t;
34-
35-
std::remove_cvref_t<Sndr> sndr;
36-
std::remove_cvref_t<Tok> tok;
37-
38-
template <::beman::execution::receiver Rcvr>
39-
struct state {
40-
using operation_state_concept = ::beman::execution::operation_state_t;
41-
using rcvr_t = ::std::remove_cvref_t<Rcvr>;
42-
using token1_t = ::std::remove_cvref_t<Tok>;
43-
using token2_t =
44-
decltype(::beman::execution::get_stop_token(::beman::execution::get_env(::std::declval<rcvr_t>())));
45-
46-
struct cb_t {
47-
::beman::execution::inplace_stop_source& source;
48-
auto operator()() const noexcept { this->source.request_stop(); }
49-
};
50-
struct base_state {
51-
rcvr_t rcvr;
52-
::beman::execution::inplace_stop_source source{};
53-
};
54-
struct env {
55-
base_state* st;
56-
auto query(const ::beman::execution::get_stop_token_t&) const noexcept {
57-
return this->st->source.get_token();
58-
}
59-
template <typename Q, typename... A>
60-
requires requires(const Q& q, A&&... a, const rcvr_t& r) {
61-
q(::beman::execution::get_env(r), ::std::forward<A>(a)...);
62-
}
63-
auto query(const Q& q, A&&... a) const noexcept {
64-
return q(::beman::execution::get_env(this->st->rcvr), ::std::forward<A>(a)...);
65-
}
66-
};
67-
68-
struct receiver {
69-
using receiver_concept = ::beman::execution::receiver_t;
70-
base_state* st;
71-
72-
auto get_env() const noexcept -> env { return env{this->st}; }
73-
template <typename... A>
74-
auto set_value(A&&... a) const noexcept -> void {
75-
::beman::execution::set_value(::std::move(this->st->rcvr), ::std::forward<A>(a)...);
76-
}
77-
template <typename E>
78-
auto set_error(E&& e) const noexcept -> void {
79-
::beman::execution::set_error(::std::move(this->st->rcvr), ::std::forward<E>(e));
80-
}
81-
auto set_stopped() const noexcept -> void {
82-
::beman::execution::set_stopped(::std::move(this->st->rcvr));
83-
}
84-
};
85-
using inner_state_t =
86-
decltype(::beman::execution::connect(::std::declval<Sndr>(), ::std::declval<receiver>()));
87-
88-
token1_t tok;
89-
base_state base;
90-
std::optional<::beman::execution::stop_callback_for_t<token1_t, cb_t>> cb1;
91-
std::optional<::beman::execution::stop_callback_for_t<token2_t, cb_t>> cb2;
92-
inner_state_t inner_state;
93-
94-
template <::beman::execution::sender S,
95-
::beman::execution::stoppable_token T,
96-
::beman::execution::receiver R>
97-
state(S&& s, T&& t, R&& r)
98-
: tok(::std::forward<T>(t)),
99-
base{::std::forward<R>(r)},
100-
inner_state(::beman::execution::connect(::std::forward<S>(s), receiver(&this->base))) {}
101-
102-
auto start() & noexcept {
103-
this->cb1.emplace(this->tok, cb_t(this->base.source));
104-
this->cb2.emplace(::beman::execution::get_stop_token(::beman::execution::get_env(this->base.rcvr)),
105-
cb_t(this->base.source));
106-
::beman::execution::start(this->inner_state);
107-
}
108-
};
109-
110-
template <typename E>
111-
auto get_completion_signatures(const E& e) const noexcept {
112-
return ::beman::execution::get_completion_signatures(this->sndr, e);
113-
}
114-
template <::beman::execution::receiver Rcvr>
115-
auto connect(Rcvr&& rcvr) && -> state<Rcvr> {
116-
return state<Rcvr>{std::move(this->sndr), ::std::move(this->tok), ::std::forward<Rcvr>(rcvr)};
117-
}
118-
};
32+
struct sender;
11933

12034
template <::beman::execution::sender Sndr, ::beman::execution::stoppable_token Tok>
12135
auto operator()(Sndr&& sndr, Tok&& tok) const noexcept {
12236
if constexpr (::beman::execution::unstoppable_token<Tok>) {
12337
return ::std::forward<Sndr>(sndr);
12438
} else {
125-
return sender<Sndr, Tok>(::std::forward<Sndr>(sndr), ::std::forward<Tok>(tok));
39+
return sender<Sndr, Tok>(*this, ::std::forward<Tok>(tok), ::std::forward<Sndr>(sndr));
12640
}
12741
}
12842
} stop_when{};
12943
} // namespace beman::execution::detail
13044

45+
template <::beman::execution::sender Sndr, ::beman::execution::stoppable_token Tok>
46+
struct beman::execution::detail::stop_when_t::sender {
47+
using sender_concept = ::beman::execution::sender_t;
48+
49+
stop_when_t stop_when{};
50+
std::remove_cvref_t<Tok> tok;
51+
std::remove_cvref_t<Sndr> sndr;
52+
53+
template <::beman::execution::receiver Rcvr>
54+
struct state {
55+
using operation_state_concept = ::beman::execution::operation_state_t;
56+
using rcvr_t = ::std::remove_cvref_t<Rcvr>;
57+
using token1_t = ::std::remove_cvref_t<Tok>;
58+
using token2_t =
59+
decltype(::beman::execution::get_stop_token(::beman::execution::get_env(::std::declval<rcvr_t>())));
60+
61+
struct cb_t {
62+
::beman::execution::inplace_stop_source& source;
63+
auto operator()() const noexcept { this->source.request_stop(); }
64+
};
65+
struct base_state {
66+
rcvr_t rcvr;
67+
::beman::execution::inplace_stop_source source{};
68+
};
69+
struct env {
70+
base_state* st;
71+
auto query(const ::beman::execution::get_stop_token_t&) const noexcept {
72+
return this->st->source.get_token();
73+
}
74+
template <typename Q, typename... A>
75+
requires requires(const Q& q, A&&... a, const rcvr_t& r) {
76+
q(::beman::execution::get_env(r), ::std::forward<A>(a)...);
77+
}
78+
auto query(const Q& q, A&&... a) const noexcept {
79+
return q(::beman::execution::get_env(this->st->rcvr), ::std::forward<A>(a)...);
80+
}
81+
};
82+
83+
struct receiver {
84+
using receiver_concept = ::beman::execution::receiver_t;
85+
base_state* st;
86+
87+
auto get_env() const noexcept -> env { return env{this->st}; }
88+
template <typename... A>
89+
auto set_value(A&&... a) const noexcept -> void {
90+
::beman::execution::set_value(::std::move(this->st->rcvr), ::std::forward<A>(a)...);
91+
}
92+
template <typename E>
93+
auto set_error(E&& e) const noexcept -> void {
94+
::beman::execution::set_error(::std::move(this->st->rcvr), ::std::forward<E>(e));
95+
}
96+
auto set_stopped() const noexcept -> void { ::beman::execution::set_stopped(::std::move(this->st->rcvr)); }
97+
};
98+
using inner_state_t =
99+
decltype(::beman::execution::connect(::std::declval<Sndr>(), ::std::declval<receiver>()));
100+
101+
token1_t tok;
102+
base_state base;
103+
std::optional<::beman::execution::stop_callback_for_t<token1_t, cb_t>> cb1;
104+
std::optional<::beman::execution::stop_callback_for_t<token2_t, cb_t>> cb2;
105+
inner_state_t inner_state;
106+
107+
template <::beman::execution::sender S, ::beman::execution::stoppable_token T, ::beman::execution::receiver R>
108+
state(S&& s, T&& t, R&& r)
109+
: tok(::std::forward<T>(t)),
110+
base{::std::forward<R>(r)},
111+
inner_state(::beman::execution::connect(::std::forward<S>(s), receiver(&this->base))) {}
112+
113+
auto start() & noexcept {
114+
this->cb1.emplace(this->tok, cb_t(this->base.source));
115+
this->cb2.emplace(::beman::execution::get_stop_token(::beman::execution::get_env(this->base.rcvr)),
116+
cb_t(this->base.source));
117+
::beman::execution::start(this->inner_state);
118+
}
119+
};
120+
121+
template <typename E>
122+
auto get_completion_signatures(const E& e) const noexcept {
123+
return ::beman::execution::get_completion_signatures(this->sndr, e);
124+
}
125+
template <::beman::execution::receiver Rcvr>
126+
auto connect(Rcvr&& rcvr) && -> state<Rcvr> {
127+
return state<Rcvr>{std::move(this->sndr), ::std::move(this->tok), ::std::forward<Rcvr>(rcvr)};
128+
}
129+
};
131130
// ----------------------------------------------------------------------------
132131

133132
#endif

0 commit comments

Comments
 (0)