fix(util/cancellable): actually set interrupt flag

This commit is contained in:
Gabriel Ebner 2017-03-01 18:31:22 +01:00
parent d0cc6f16b1
commit b6e79d646d
2 changed files with 8 additions and 2 deletions

View file

@ -49,7 +49,10 @@ cancellation_token mk_cancellation_token(cancellation_token const & parent) {
LEAN_THREAD_PTR(cancellation_token const, g_cancellation_token);
scope_cancellation_token::scope_cancellation_token(cancellation_token const * tok) :
flet<cancellation_token const *>(g_cancellation_token, tok) {}
flet<cancellation_token const *>(g_cancellation_token, tok),
scoped_interrupt_flag(*tok ? (*tok)->get_cancellation_flag() : nullptr) {
check_interrupted();
}
cancellation_token global_cancellation_token() {
return g_cancellation_token ? *g_cancellation_token : nullptr;

View file

@ -9,6 +9,7 @@ Author: Gabriel Ebner
#include <vector>
#include "util/thread.h"
#include "util/flet.h"
#include "interrupt.h"
namespace lean {
@ -36,6 +37,8 @@ public:
void gc();
void cancel(std::shared_ptr<cancellable> const & self) override;
atomic_bool * get_cancellation_flag() { return &m_cancelled; }
};
cancellation_token mk_cancellation_token(cancellation_token const & parent);
@ -44,7 +47,7 @@ inline cancellation_token mk_cancellation_token() { return mk_cancellation_token
inline void cancel(std::shared_ptr<cancellable> const & c) { if (c) c->cancel(c); }
inline void cancelw(std::weak_ptr<cancellable> const & wc) { if (auto c = wc.lock()) cancel(c); }
struct scope_cancellation_token : flet<cancellation_token const *> {
struct scope_cancellation_token : flet<cancellation_token const *>, scoped_interrupt_flag {
scope_cancellation_token(cancellation_token const *);
scope_cancellation_token(cancellation_token & t) : scope_cancellation_token(&t) {}
};