56using concurrency::cancel_current_task;
57using concurrency::cancellation_token;
58using concurrency::cancellation_token_registration;
59using concurrency::cancellation_token_source;
60using concurrency::task_canceled;
75 typedef std::list<std::function<void()>> list_type;
77 cancel_state() : canceled_(
false) {}
82 std::lock_guard<std::mutex> lock(guard_);
85 swap(list, callback_list_);
88 for (
const auto& f : list)
99 list.push_back(std::move(f));
103 std::lock_guard<std::mutex> lock(guard_);
104 canceled = canceled_;
110 callback_list_.splice(begin(callback_list_), list);
111 result = &callback_list_.back();
127 std::lock_guard<std::mutex> lock(guard_);
129 auto i =
find_if(begin(callback_list_), end(callback_list_),
130 [token](
const std::function<
void()>& x) {
return &x == token; });
131 if (i != end(callback_list_))
132 list.splice(end(list), callback_list_, i);
136 bool is_canceled()
const {
return canceled_; }
139 volatile bool canceled_;
140 list_type callback_list_;
149class cancellation_token_source;
151class cancellation_token {
153 template <
typename F>
155 return state_ ? state_->register_callback(std::move(f)) :
nullptr;
160 state_->deregister_callback(token);
166 bool is_canceled()
const {
return state_ ? state_->is_canceled() :
false; }
168 static cancellation_token
none() {
return cancellation_token(); }
170 friend inline bool operator==(
const cancellation_token& x,
const cancellation_token& y) {
171 return x.state_ == y.state_;
176 cancellation_token() {}
179 std::shared_ptr<detail::cancel_state> state_;
192 void cancel()
const { state_->cancel(); }
198 return x.state_ == y.state_;
202 std::shared_ptr<detail::cancel_state> state_;
215 const char*
what() const noexcept {
return what_.empty() ?
"task_canceled" : what_.c_str(); }
cancellation_token_source()
friend bool operator==(const cancellation_token_source &x, const cancellation_token_source &y)
cancellation_token get_token() const
static cancellation_token none()
bool is_cancelable() const
cancellation_token_registration register_callback(F f) const
friend class cancellation_token_source
friend bool operator==(const cancellation_token &x, const cancellation_token &y)
void deregister_callback(const cancellation_token_registration &token) const
const char * what() const noexcept
task_canceled(const char *message)
InputIterator find_if(InputIterator first, InputIterator last, Predicate pred)
find implementation
void swap(any_regular_t &x, any_regular_t &y)
std::function< void()> * cancellation_token_registration
bool operator!=(const forest< T > &x, const forest< T > &y)
void cancel_current_task()