Skip to content

Commit a17882c

Browse files
committed
Merge branch 'main' into v0.60
2 parents 64b5d43 + cd3a7ac commit a17882c

File tree

89 files changed

+2057
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2057
-544
lines changed

Common/Cpp/CancellableScope.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <mutex>
1111
#include <condition_variable>
1212
#include "Exceptions.h"
13+
#include "ListenerSet.h"
1314
#include "Containers/Pimpl.tpp"
1415
#include "Concurrency/SpinLock.h"
1516
#include "CancellableScope.h"
@@ -28,9 +29,17 @@ struct CancellableData{
2829
std::atomic<bool> cancelled;
2930
mutable SpinLock lock;
3031
std::exception_ptr exception;
32+
ListenerSet<Cancellable::CancelListener> m_listeners;
3133
};
3234

3335

36+
void Cancellable::add_cancel_listener(CancelListener& listener){
37+
m_impl->m_listeners.add(listener);
38+
}
39+
void Cancellable::remove_cancel_listener(CancelListener& listener){
40+
m_impl->m_listeners.remove(listener);
41+
}
42+
3443

3544
Cancellable::Cancellable()
3645
: m_impl(CONSTRUCT_TOKEN)
@@ -56,10 +65,15 @@ bool Cancellable::cancel(std::exception_ptr exception) noexcept{
5665
if (exception && !data.exception){
5766
data.exception = std::move(exception);
5867
}
59-
if (data.cancelled.load(std::memory_order_acquire)){
68+
if (data.cancelled.load(std::memory_order_relaxed)){
6069
return true;
6170
}
62-
return data.cancelled.exchange(true, std::memory_order_relaxed);
71+
data.cancelled.store(true, std::memory_order_release);
72+
// if (data.cancelled.exchange(true, std::memory_order_relaxed)){
73+
// return true;
74+
// }
75+
m_impl->m_listeners.run_method(&CancelListener::on_cancellable_cancel);
76+
return false;
6377
}
6478
void Cancellable::throw_if_cancelled() const{
6579
auto scope_check = m_sanitizer.check_scope();

Common/Cpp/CancellableScope.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ struct CancellableData;
4545
class Cancellable{
4646
Cancellable(const Cancellable&) = delete;
4747
void operator=(const Cancellable&) = delete;
48+
public:
49+
struct CancelListener{
50+
virtual void on_cancellable_cancel() = 0;
51+
};
52+
void add_cancel_listener(CancelListener& listener);
53+
void remove_cancel_listener(CancelListener& listener);
54+
55+
4856
public:
4957
virtual ~Cancellable();
5058

0 commit comments

Comments
 (0)