From a3c72b0e3c8b6abcbc7e4939819441e114c23ff3 Mon Sep 17 00:00:00 2001 From: syntheticmagus <33846034+syntheticmagus@users.noreply.github.com> Date: Tue, 3 May 2022 10:05:14 -0700 Subject: [PATCH 1/3] Fixing cancel listeners forgotten when name changed. --- Source/Shared/arcana/scheduling/state_machine.h | 4 ++-- Source/Shared/arcana/threading/dispatcher.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Shared/arcana/scheduling/state_machine.h b/Source/Shared/arcana/scheduling/state_machine.h index a85c314..731c4e6 100644 --- a/Source/Shared/arcana/scheduling/state_machine.h +++ b/Source/Shared/arcana/scheduling/state_machine.h @@ -34,7 +34,7 @@ namespace arcana stateTasks.StateEntered->complete(expected::make_valid()); - std::shared_ptr listener = std::make_shared(cancel.add_listener([this, &state] + std::shared_ptr listener = std::make_shared(cancel.add_cancellation_requested_listener([this, &state] { cancel_exit(state); })); @@ -74,7 +74,7 @@ namespace arcana stateTasks = completion; } - std::shared_ptr listener = std::make_shared(cancel.add_listener([this, &state] + std::shared_ptr listener = std::make_shared(cancel.add_cancellation_requested_listener([this, &state] { cancel_enter(state); })); diff --git a/Source/Shared/arcana/threading/dispatcher.h b/Source/Shared/arcana/threading/dispatcher.h index fbcb4b0..e558d12 100644 --- a/Source/Shared/arcana/threading/dispatcher.h +++ b/Source/Shared/arcana/threading/dispatcher.h @@ -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{ [&]() { From b400d93921c900044cc6eaf988009d21e7cc1efe Mon Sep 17 00:00:00 2001 From: syntheticmagus <33846034+syntheticmagus@users.noreply.github.com> Date: Tue, 3 May 2022 10:20:36 -0700 Subject: [PATCH 2/3] Removed operator clang was complaining about. --- Source/Shared/arcana/threading/cancellation.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Source/Shared/arcana/threading/cancellation.h b/Source/Shared/arcana/threading/cancellation.h index dd1cf3d..278e4bf 100644 --- a/Source/Shared/arcana/threading/cancellation.h +++ b/Source/Shared/arcana/threading/cancellation.h @@ -177,7 +177,7 @@ namespace arcana return ticket{ [] {} }; std::function copied; - ticket result{ m_impl->add_listener(callback, copied) }; + ticket result{ m_impl->add_cancellation_requested_listener(callback, copied) }; if (copied) copied(); @@ -233,11 +233,6 @@ 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> future{}; From 80d4989320963675c4fe01576b4df438c97910d2 Mon Sep 17 00:00:00 2001 From: syntheticmagus <33846034+syntheticmagus@users.noreply.github.com> Date: Tue, 3 May 2022 10:49:22 -0700 Subject: [PATCH 3/3] Fixing problem with blocking cancel. --- Source/Shared/arcana/threading/cancellation.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Shared/arcana/threading/cancellation.h b/Source/Shared/arcana/threading/cancellation.h index 278e4bf..51feb68 100644 --- a/Source/Shared/arcana/threading/cancellation.h +++ b/Source/Shared/arcana/threading/cancellation.h @@ -235,21 +235,21 @@ namespace arcana void cancel(bool blockUntilCompleted = false) { - std::optional> future{}; + std::optional> promise{}; + std::optional ticket{}; if (blockUntilCompleted) { - std::promise 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(); } } };