Lely core libraries  2.3.4
lely::util::StopCallback< Callback > Class Template Reference

A RAII object type that registers a callback function with a lely::util::StopToken object. More...

#include <stop.hpp>

Inheritance diagram for lely::util::StopCallback< Callback >:
Collaboration diagram for lely::util::StopCallback< Callback >:

Public Member Functions

template<class C >
 StopCallback (const StopToken &token, C &&cb)
 Copies the token stop token, saves the cb callback function and registers with with token. More...
 
template<class C >
 StopCallback (StopToken &&token, C &&cb)
 Moves the token stop token, saves the cb callback function and registers with with token. More...
 
 ~StopCallback ()
 If *this has a lely::util::StopToken with associated stop-state, deregisters the saved callback function from it. More...
 

Additional Inherited Members

- Data Fields inherited from stop_func
void(* func )(struct stop_func *func)
 The function to be invoked when a stop request is issued.
 

Detailed Description

template<class Callback>
class lely::util::StopCallback< Callback >

A RAII object type that registers a callback function with a lely::util::StopToken object.

The callback function will be invoked when the lely::util::StopSource object associated with the stop token is requested to stop.

Definition at line 349 of file stop.hpp.

Constructor & Destructor Documentation

◆ StopCallback() [1/2]

template<class Callback >
template<class C >
lely::util::StopCallback< Callback >::StopCallback ( const StopToken token,
C &&  cb 
)
inlineexplicit

Copies the token stop token, saves the cb callback function and registers with with token.

If a stop request has already been issued for the associated lely::util::StopSource object, the callback function is invoked in the calling thread before the constructor returns.

See also
stop_token_insert()

Definition at line 362 of file stop.hpp.

◆ StopCallback() [2/2]

template<class Callback >
template<class C >
lely::util::StopCallback< Callback >::StopCallback ( StopToken &&  token,
C &&  cb 
)
inlineexplicit

Moves the token stop token, saves the cb callback function and registers with with token.

If a stop request has already been issued for the associated lely::util::StopSource object, the callback function is invoked in the calling thread before the constructor returns.

See also
stop_token_insert()

Definition at line 376 of file stop.hpp.

◆ ~StopCallback()

template<class Callback >
lely::util::StopCallback< Callback >::~StopCallback ( )
inline

If *this has a lely::util::StopToken with associated stop-state, deregisters the saved callback function from it.

If the callback function is being invoked concurrently on another thread, the destructor does not return until the callback function invocation is complete. If the callback function is being invoked on the calling thread, the destructor does not wait until the invocation is complete. Hence it is safe to invoke the destructor from the callback function.

See also
stop_token_remove()

Definition at line 398 of file stop.hpp.


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