Loading...
Searching...
No Matches
eonc::CancelToken Class Reference

Shared flag. Copies observe the same request. More...

#include <CancelToken.h>

Public Member Functions

 CancelToken ()
void request () noexcept
void reset () noexcept
bool requested () const noexcept
void poll (const char *site="step") const

Private Attributes

std::shared_ptr< std::atomic< bool > > flag_

Detailed Description

Shared flag. Copies observe the same request.

Definition at line 30 of file CancelToken.h.

Constructor & Destructor Documentation

◆ CancelToken()

eonc::CancelToken::CancelToken ( )
inline

Definition at line 32 of file CancelToken.h.

32: flag_(std::make_shared<std::atomic<bool>>(false)) {}
std::shared_ptr< std::atomic< bool > > flag_
Definition CancelToken.h:57

Member Function Documentation

◆ poll()

void eonc::CancelToken::poll ( const char * site = "step") const
inline

Definition at line 50 of file CancelToken.h.

50 {
51 if (requested()) {
52 throw JobCancelled(site);
53 }
54 }
bool requested() const noexcept
Definition CancelToken.h:46

◆ request()

void eonc::CancelToken::request ( )
inlinenoexcept

Definition at line 34 of file CancelToken.h.

34 {
35 if (flag_) {
36 flag_->store(true, std::memory_order_release);
37 }
38 }

◆ requested()

bool eonc::CancelToken::requested ( ) const
inlinenodiscardnoexcept

Definition at line 46 of file CancelToken.h.

46 {
47 return flag_ && flag_->load(std::memory_order_acquire);
48 }

◆ reset()

void eonc::CancelToken::reset ( )
inlinenoexcept

Definition at line 40 of file CancelToken.h.

40 {
41 if (flag_) {
42 flag_->store(false, std::memory_order_release);
43 }
44 }

Member Data Documentation

◆ flag_

std::shared_ptr<std::atomic<bool> > eonc::CancelToken::flag_
private

Definition at line 57 of file CancelToken.h.


The documentation for this class was generated from the following file: