Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Source/Shared/arcana/scheduling/state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace arcana

stateTasks.StateEntered->complete(expected<void, std::error_code>::make_valid());

std::shared_ptr<cancellation_data> listener = std::make_shared<cancellation_data>(cancel.add_listener([this, &state]
std::shared_ptr<cancellation_data> listener = std::make_shared<cancellation_data>(cancel.add_cancellation_requested_listener([this, &state]
{
cancel_exit(state);
}));
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace arcana
stateTasks = completion;
}

std::shared_ptr<cancellation_data> listener = std::make_shared<cancellation_data>(cancel.add_listener([this, &state]
std::shared_ptr<cancellation_data> listener = std::make_shared<cancellation_data>(cancel.add_cancellation_requested_listener([this, &state]
{
cancel_enter(state);
}));
Expand Down
23 changes: 9 additions & 14 deletions Source/Shared/arcana/threading/cancellation.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace arcana
return ticket{ [] {} };

std::function<void()> copied;
ticket result{ m_impl->add_listener(callback, copied) };
ticket result{ m_impl->add_cancellation_requested_listener(callback, copied) };

if (copied)
copied();
Expand Down Expand Up @@ -233,28 +233,23 @@ namespace arcana
cancellation_source(const cancellation_source&) = delete;
cancellation_source(cancellation_source&&) = delete;

operator cancellation()
{
return { m_impl };
}

void cancel(bool blockUntilCompleted = false)
{
std::optional<std::future<void>> future{};
std::optional<std::promise<void>> promise{};
std::optional<cancellation::ticket> ticket{};
if (blockUntilCompleted)
{
std::promise<void> promise{};
future.emplace(promise.get_future());
auto ticket = add_cancellation_completed_listener([&promise]() {
promise.set_value();
});
promise.emplace();
ticket.emplace(add_cancellation_completed_listener([&promise]() {
promise.value().set_value();
}));
}

m_impl->unsafe_cancel();

if (future)
if (promise)
{
future.value().wait();
promise.value().get_future().wait();
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Shared/arcana/threading/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace arcana
{
public:
background_dispatcher()
: m_registration{ m_cancellation.add_listener([this] { this->cancelled(); }) }
: m_registration{ m_cancellation.add_cancellation_requested_listener([this] { this->cancelled(); }) }
{
m_thread = std::thread{ [&]() {

Expand Down