Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions include/stdexec/__detail/__sync_wait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "__run_loop.hpp"
#include "__type_traits.hpp"

#include "__atomic.hpp"

#include <exception>
#include <system_error>
#include <optional>
Expand Down Expand Up @@ -89,6 +91,17 @@ namespace stdexec {
struct __state {
std::exception_ptr __eptr_;
run_loop __loop_;
stdexec::__std::atomic<bool> __done_{false};

void finish() noexcept {
__loop_.finish();
__done_.store(true, stdexec::__std::memory_order_release);
__done_.notify_all();
}

void wait() noexcept {
__done_.wait(false, stdexec::__std::memory_order_acquire);
}
};

template <class... _Values>
Expand All @@ -108,7 +121,7 @@ namespace stdexec {
STDEXEC_CATCH_ALL {
__state_->__eptr_ = std::current_exception();
}
__state_->__loop_.finish();
__state_->finish();
}

template <class _Error>
Expand All @@ -121,11 +134,11 @@ namespace stdexec {
} else {
__state_->__eptr_ = std::make_exception_ptr(static_cast<_Error&&>(__err));
}
__state_->__loop_.finish();
__state_->finish();
}

void set_stopped() noexcept {
__state_->__loop_.finish();
__state_->finish();
}

[[nodiscard]]
Expand Down Expand Up @@ -286,6 +299,7 @@ namespace stdexec {

// Wait for the variant to be filled in.
__local_state.__loop_.run();
__local_state.wait();

if (__local_state.__eptr_) {
std::rethrow_exception(static_cast<std::exception_ptr&&>(__local_state.__eptr_));
Expand Down