Skip to content

Commit

Permalink
Eagerly release predecessor operation state in let_value
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Nov 6, 2024
1 parent 6ac54ed commit 93d6d6f
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace pika::let_value_detail {

// Operation state from connecting predecessor sender to
// let_value_predecessor_receiver
predecessor_operation_state_type predecessor_op_state;
std::optional<predecessor_operation_state_type> predecessor_op_state;

using predecessor_ts_type = pika::util::detail::prepend_t<
predecessor_value_types<std::tuple, pika::detail::variant>,
Expand Down Expand Up @@ -158,12 +158,14 @@ namespace pika::let_value_detail {
{
pika::execution::experimental::set_error(
PIKA_MOVE(r.receiver), PIKA_FORWARD(Error, error));
r.op_state.predecessor_op_state.reset();
}

friend void tag_invoke(pika::execution::experimental::set_stopped_t,
let_value_predecessor_receiver&& r) noexcept
{
pika::execution::experimental::set_stopped(PIKA_MOVE(r.receiver));
r.op_state.predecessor_op_state.reset();
};

struct start_visitor
Expand Down Expand Up @@ -238,6 +240,7 @@ namespace pika::let_value_detail {
op_state.predecessor_ts
.template emplace<std::tuple<std::decay_t<Ts>...>>(
PIKA_FORWARD(Ts, ts)...);
// op_state.predecessor_op_state.reset();
pika::detail::visit(
set_value_visitor{PIKA_MOVE(receiver), PIKA_MOVE(f), op_state},
op_state.predecessor_ts);
Expand Down Expand Up @@ -266,10 +269,12 @@ namespace pika::let_value_detail {

template <typename PredecessorSender_, typename Receiver_, typename F_>
operation_state(PredecessorSender_&& predecessor_sender, Receiver_&& receiver, F_&& f)
: predecessor_op_state{pika::execution::experimental::connect(
PIKA_FORWARD(PredecessorSender_, predecessor_sender),
let_value_predecessor_receiver(
PIKA_FORWARD(Receiver_, receiver), PIKA_FORWARD(F_, f), *this))}
: predecessor_op_state(pika::detail::with_result_of([&]() {
return pika::execution::experimental::connect(
PIKA_FORWARD(PredecessorSender_, predecessor_sender),
let_value_predecessor_receiver(
PIKA_FORWARD(Receiver_, receiver), PIKA_FORWARD(F_, f), *this));
}))
{
}

Expand All @@ -281,7 +286,7 @@ namespace pika::let_value_detail {
friend void tag_invoke(
pika::execution::experimental::start_t, operation_state& os) noexcept
{
pika::execution::experimental::start(os.predecessor_op_state);
pika::execution::experimental::start(*os.predecessor_op_state);
}
};

Expand Down

0 comments on commit 93d6d6f

Please sign in to comment.