24#ifndef LELY_UTIL_STOP_HPP_
25#define LELY_UTIL_STOP_HPP_
71 other.token_ =
nullptr;
83 if (token_ != other.token_) {
100 swap(token_, other.token_);
112 operator stop_token_t*()
const noexcept {
return token_; }
115 explicit operator bool() const noexcept {
return token_ !=
nullptr; }
143 ::std::swap(token_, other.token_);
152 return lhs.token_ == rhs.token_;
161 return !(lhs == rhs);
187 if (!source_) util::throw_errc(
"StopSource");
216 other.source_ =
nullptr;
228 if (source_ != other.source_) {
259 explicit operator bool() const noexcept {
return source_ !=
nullptr; }
302 ::std::swap(source_, other.source_);
320 return lhs.source_ == rhs.source_;
329 return !(lhs == rhs);
348template <
class Callback>
351 using callback_type = Callback;
406 ::std::forward<Callback>(cb_)();
A RAII object type that registers a callback function with a lely::util::StopToken object.
StopCallback(const StopToken &token, C &&cb)
Copies the token stop token, saves the cb callback function and registers with with token.
~StopCallback()
If *this has a lely::util::StopToken with associated stop-state, deregisters the saved callback funct...
StopCallback(StopToken &&token, C &&cb)
Moves the token stop token, saves the cb callback function and registers with with token.
An object providing the means to issue a stop request.
friend void swap(StopSource &lhs, StopSource &rhs) noexcept
Exchanges the stop-state of lhs with rhs.
StopSource(StopSource &&other) noexcept
Constructs a stop source whose associated stop-state is the same as that if other; other is left as v...
StopToken get_token() const noexcept
Returns a stop token associated with the stop-state of *this, if it has any, and a default-constructe...
~StopSource()
Destroys a stop source.
StopSource(const StopSource &other) noexcept
Constructs a stop source whose associated stop-state is the same as that if other.
StopSource & operator=(const StopSource &other) noexcept
Copy-assigns the stop-state of other to *this.
StopSource(stop_source_t *source) noexcept
Constructs an empty stop source with no assiociated stop-state.
StopSource()
Constructs a stop source with a new stop-state.
friend bool operator==(const StopSource &lhs, const StopSource &rhs) noexcept
Returns true if lhs and rhs have the same stop-state, and false otherwise.
bool stop_possible() const noexcept
Returns true if *this has a stop-state, and false otherwise.
friend bool operator!=(const StopSource &lhs, const StopSource &rhs) noexcept
Returns false if lhs and rhs have the same stop-state, and true otherwise.
StopSource & operator=(StopSource &&other) noexcept
Move-assigns the stop-state of other to *this.
bool stop_requested() const noexcept
Returns true if *this has a stop-state and it has received a stop request, and false otherwise.
void swap(StopSource &other) noexcept
Exchanges the stop-state of *this and other/.
bool request_stop() noexcept
Issues a stop requests to the stop-state, if *this has a stop-state` and it has not already received ...
An object providing the means to check if a stop request has been made for its associated lely::util:...
StopToken(const StopToken &other) noexcept
Constructs a stop token whose associated stop-state is the same as that if other.
StopToken & operator=(const StopToken &other) noexcept
Copy-assigns the stop-state of other to *this.
~StopToken()
Destroys a stop token.
friend void swap(StopToken &lhs, StopToken &rhs) noexcept
Exchanges the stop-state of lhs with rhs.
friend bool operator==(const StopToken &lhs, const StopToken &rhs) noexcept
Returns true if lhs and rhs have the same stop-state, and false otherwise.
StopToken(StopToken &&other) noexcept
Constructs a stop token whose associated stop-state is the same as that if other; other is left as va...
bool stop_possible() const noexcept
Returns true if *this has a stop-state and it has received a stop request, or if it has an associated...
void swap(StopToken &other) noexcept
Exchanges the stop-state of *this and other/.
friend bool operator!=(const StopToken &lhs, const StopToken &rhs) noexcept
Returns false if lhs and rhs have the same stop-state, and true otherwise.
bool stop_requested() const noexcept
Returns true if *this has a stop-state and it has received a stop request, and false otherwise.
StopToken() noexcept=default
Constructs an empty stop token with no assiociated stop-state.
StopToken & operator=(StopToken &&other) noexcept
Move-assigns the stop-state of other to *this.
This header file is part of the utilities library; it contains C++ convenience functions for creating...
This header file is part of the utilities library; it contains the stop token declarations.
int stop_token_insert(stop_token_t *token, struct stop_func *func)
Registers a callback function with the specified stop token.
#define STOP_FUNC_INIT(func)
The static initializer for stop_func.
void stop_token_release(stop_token_t *token)
Releases a reference to a stop token.
int stop_source_request_stop(stop_source_t *source)
Issues a stop request to the stop-state associated with the specified stop source,...
stop_token_t * stop_source_get_token(stop_source_t *source)
Returns (a reference to) a stop token associated with the specified stop source's stop-state.
stop_source_t * stop_source_acquire(stop_source_t *source)
Acquires a reference to a stop source.
void stop_source_release(stop_source_t *source)
Releases a reference to a stop source.
int stop_source_stop_requested(const stop_source_t *source)
Checks if the stop-state associated with the specified stop source has received a stop request.
void stop_token_remove(stop_token_t *token, struct stop_func *func)
Deregisters a callback function from the specified stop token.
int stop_token_stop_possible(const stop_token_t *token)
Checks if the stop-state associated with the specified stop token has received a stop request,...
stop_source_t * stop_source_create(void)
Creates a stop source with a new stop-state.
int stop_token_stop_requested(const stop_token_t *token)
Checks if the stop-state associated with the specified stop token has received a stop request.
stop_token_t * stop_token_acquire(stop_token_t *token)
Acquires a reference to a stop token.
An object providing the means to register a callback function with an stop_token_t object.
void(* func)(struct stop_func *func)
The function to be invoked when a stop request is issued.