Async 1.8.0
Async::ThreadSigCSignal< T_ret, Args > Class Template Reference

A threadsafe SigC signal. More...

#include <AsyncThreadSigCSignal.h>

Public Types

enum  Mode { NON_SYNCHRONOUS , SYNCHRONOUS }
 
typedef T_ret result_type
 
typedef sigc::slot< T_ret, Args... > slot_type
 
typedef sigc::slot_list< slot_typeslot_list_type
 
typedef sigc::signal< T_ret, Args... > signal_type
 
typedef signal_type::iterator iterator
 
typedef signal_type::const_iterator const_iterator
 

Public Member Functions

 ThreadSigCSignal (Mode mode=NON_SYNCHRONOUS)
 Constructor.
 
 ThreadSigCSignal (const ThreadSigCSignal &)=delete
 The copy constructor is deleted.
 
 ~ThreadSigCSignal (void)
 Destructor.
 
ThreadSigCSignaloperator= (const ThreadSigCSignal &)=delete
 The assignment operator is deleted.
 
iterator connect (const slot_type &slt)
 Connect this signal to the given slot.
 
template<typename... T>
result_type emit (T &&... args)
 Queue the emission of this signal.
 
template<typename... T>
result_type emit_reverse (T &&... args)
 Queue the emission of this signal in reverse order.
 
template<typename... T>
result_type operator() (T &&... args)
 Queue the emission of this signal.
 
slot_type make_slot (void)
 Return a slot that emits this signal.
 
slot_list_type slots (void)
 Return a list of the connected slots.
 
const slot_list_type slots (void) const
 Return a list of the connected slots.
 

Detailed Description

template<typename T_ret, typename... Args>
class Async::ThreadSigCSignal< T_ret, Args >

A threadsafe SigC signal.

Author
Tobias Blomberg / SM0SVX
Date
2019-02-02

This class is implemented as close as possible to mimic a sigc::signal but with thread safety in mind. When the signal is emitted, instead of calling it directly, it will be added to a queue. The queue is then processed from the Async main thread in a safe manner so that all connected slots are called from the main thread.

There also is a synchrorous mode where the queue is not used and the connected slot is called directly after grabbing an Async::Mutex lock. The negative side of using synchronous mode is that all threads wanting to grab an Async::Mutex will block until the signal emission processing have finished. It probably is best to not use synchronous mode in most cases. One case where synchronouns mode have to be used is if the return value of the connected slot(s) is important since the non-synchronous mode cannot provide the signal emitter with the return value from the connected slot(s).

If the signal is emitted from the main Async thread it will still be queued so this may be used if a signal emission need to be delayed so that it is called from the main Async loop. Note that if synchronous mode has been activated the queue will not be used and the signal will behave like a normal sigc::signal.

Definition at line 140 of file AsyncThreadSigCSignal.h.

Member Typedef Documentation

◆ const_iterator

template<typename T_ret , typename... Args>
signal_type::const_iterator Async::ThreadSigCSignal< T_ret, Args >::const_iterator

Definition at line 148 of file AsyncThreadSigCSignal.h.

◆ iterator

template<typename T_ret , typename... Args>
signal_type::iterator Async::ThreadSigCSignal< T_ret, Args >::iterator

Definition at line 147 of file AsyncThreadSigCSignal.h.

◆ result_type

template<typename T_ret , typename... Args>
T_ret Async::ThreadSigCSignal< T_ret, Args >::result_type

Definition at line 143 of file AsyncThreadSigCSignal.h.

◆ signal_type

template<typename T_ret , typename... Args>
sigc::signal<T_ret, Args...> Async::ThreadSigCSignal< T_ret, Args >::signal_type

Definition at line 146 of file AsyncThreadSigCSignal.h.

◆ slot_list_type

template<typename T_ret , typename... Args>
sigc::slot_list<slot_type> Async::ThreadSigCSignal< T_ret, Args >::slot_list_type

Definition at line 145 of file AsyncThreadSigCSignal.h.

◆ slot_type

template<typename T_ret , typename... Args>
sigc::slot<T_ret, Args...> Async::ThreadSigCSignal< T_ret, Args >::slot_type

Definition at line 144 of file AsyncThreadSigCSignal.h.

Member Enumeration Documentation

◆ Mode

template<typename T_ret , typename... Args>
enum Async::ThreadSigCSignal::Mode
Enumerator
NON_SYNCHRONOUS 
SYNCHRONOUS 

Definition at line 150 of file AsyncThreadSigCSignal.h.

Constructor & Destructor Documentation

◆ ThreadSigCSignal() [1/2]

template<typename T_ret , typename... Args>
Async::ThreadSigCSignal< T_ret, Args >::ThreadSigCSignal ( Mode mode = NON_SYNCHRONOUS)
inline

Constructor.

Parameters
modeChoose mode of operation

If SYNCHRONOUS mode is set, when the signal is emitted it will not be queued but rather the connected slot will be called directly after grabbing an Async::Mutex lock. THe default is non-synchronous mode where the signal emission is queued.

Definition at line 161 of file AsyncThreadSigCSignal.h.

◆ ThreadSigCSignal() [2/2]

template<typename T_ret , typename... Args>
Async::ThreadSigCSignal< T_ret, Args >::ThreadSigCSignal ( const ThreadSigCSignal< T_ret, Args > & )
delete

The copy constructor is deleted.

◆ ~ThreadSigCSignal()

template<typename T_ret , typename... Args>
Async::ThreadSigCSignal< T_ret, Args >::~ThreadSigCSignal ( void )
inline

Destructor.

Definition at line 171 of file AsyncThreadSigCSignal.h.

References Async::TaskRunner::cancel().

Member Function Documentation

◆ connect()

template<typename T_ret , typename... Args>
iterator Async::ThreadSigCSignal< T_ret, Args >::connect ( const slot_type & slt)
inline

Connect this signal to the given slot.

Parameters
sltThe slot to connect to
Returns
Returns a sigc::connection object

Definition at line 188 of file AsyncThreadSigCSignal.h.

◆ emit()

template<typename T_ret , typename... Args>
template<typename... T>
result_type Async::ThreadSigCSignal< T_ret, Args >::emit ( T &&... args)
inline

Queue the emission of this signal.

Parameters
argZero or more arguments depending on the signal declaration
Returns
Always return the default value of the specified return type

This function will add a signal emission to the emission queue. Since the emission is delayed there is no way of returning the return value from the slot(s). This function will instead return the default value of the specified return type.

Definition at line 204 of file AsyncThreadSigCSignal.h.

◆ emit_reverse()

template<typename T_ret , typename... Args>
template<typename... T>
result_type Async::ThreadSigCSignal< T_ret, Args >::emit_reverse ( T &&... args)
inline

Queue the emission of this signal in reverse order.

Parameters
argZero or more arguments depending on the signal declaration
Returns
Always return the default value of the specified return type

This function will add a signal emission to the emission queue. Since the emission is delayed there is no way of returning the return value from the slot(s). This function will instead return the default value of the specified return type. The connected slots will be called in the reverse order in comparison to the order they were added.

Definition at line 222 of file AsyncThreadSigCSignal.h.

◆ make_slot()

template<typename T_ret , typename... Args>
slot_type Async::ThreadSigCSignal< T_ret, Args >::make_slot ( void )
inline

Return a slot that emits this signal.

Returns
A new slot is returned

Definition at line 247 of file AsyncThreadSigCSignal.h.

◆ operator()()

template<typename T_ret , typename... Args>
template<typename... T>
result_type Async::ThreadSigCSignal< T_ret, Args >::operator() ( T &&... args)
inline

Queue the emission of this signal.

Parameters
argZero or more arguments depending on the signal declaration
Returns
Always return the default value of the specified return type

This function will add a signal emission to the emission queue. Since the emission is delayed there is no way of returning the return value from the slot(s). This function will instead return the default value of the specified return type.

Definition at line 238 of file AsyncThreadSigCSignal.h.

◆ operator=()

template<typename T_ret , typename... Args>
ThreadSigCSignal & Async::ThreadSigCSignal< T_ret, Args >::operator= ( const ThreadSigCSignal< T_ret, Args > & )
delete

The assignment operator is deleted.

◆ slots() [1/2]

template<typename T_ret , typename... Args>
slot_list_type Async::ThreadSigCSignal< T_ret, Args >::slots ( void )
inline

Return a list of the connected slots.

Returns
The slot list is returned

Definition at line 256 of file AsyncThreadSigCSignal.h.

◆ slots() [2/2]

template<typename T_ret , typename... Args>
const slot_list_type Async::ThreadSigCSignal< T_ret, Args >::slots ( void ) const
inline

Return a list of the connected slots.

Returns
The slot list is returned

Definition at line 265 of file AsyncThreadSigCSignal.h.


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