diff --git a/base/base_tests/cancellable_tests.cpp b/base/base_tests/cancellable_tests.cpp index 3e993d50e4..760020416a 100644 --- a/base/base_tests/cancellable_tests.cpp +++ b/base/base_tests/cancellable_tests.cpp @@ -17,7 +17,7 @@ UNIT_TEST(Cancellable_Smoke) Cancellable cancellable; promise syncPromise; - auto syncFuture = promise.get_future(); + auto syncFuture = syncPromise.get_future(); double x = 0.123; diff --git a/base/cancellable.cpp b/base/cancellable.cpp index a4e8e4d429..600804b9ff 100644 --- a/base/cancellable.cpp +++ b/base/cancellable.cpp @@ -29,16 +29,14 @@ void Cancellable::SetDeadline(std::chrono::steady_clock::time_point const & dead bool Cancellable::IsCancelled() const { - std::lock_guard lock(m_mutex); - - CheckDeadline(); - return m_status != Status::Active; + return CancellationStatus() != Status::Active; } Cancellable::Status Cancellable::CancellationStatus() const { std::lock_guard lock(m_mutex); + CheckDeadline(); return m_status; } diff --git a/base/cancellable.hpp b/base/cancellable.hpp index ba333f1012..e2b3afeb7d 100644 --- a/base/cancellable.hpp +++ b/base/cancellable.hpp @@ -35,12 +35,12 @@ public: // Sets a deadline after which the activity is cancelled. virtual void SetDeadline(std::chrono::steady_clock::time_point const & t); + // Updates the status. // Returns true iff current activity has been cancelled (either by the call // to Cancel or by timeout). virtual bool IsCancelled() const; - // Returns the latest known status. Does not update the status before returning, - // i.e. may miss crossing the deadline if the latest update was too long ago. + // Updates the status of current activity and returns its value. virtual Status CancellationStatus() const; private: