distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::internal::SignalsCatcherControlBlock Class Reference

SignalsCatcherControlBlock class is a structure required by threads for "catching" and "handling" of signals. More...

#include <SignalsCatcherControlBlock.hpp>

Collaboration diagram for distortos::internal::SignalsCatcherControlBlock:
[legend]

Public Types

using Association = std::pair< SignalSet, SignalAction >
 association of signal numbers (as SignalSet) with SignalAction More...
 
using Storage = std::aligned_storage< sizeof(Association), alignof(Association)>::type
 type of uninitialized storage for Association objects More...
 
using StorageUniquePointer = std::unique_ptr< Storage[], void(&)(Storage *)>
 unique_ptr (with deleter) to Storage[] More...
 

Public Member Functions

 SignalsCatcherControlBlock (StorageUniquePointer &&storageUniquePointer, size_t storageSize)
 SignalsCatcherControlBlock's constructor. More...
 
 ~SignalsCatcherControlBlock ()
 SignalsCatcherControlBlock's destructor. More...
 
void deliveryOfSignalsStartedHook ()
 Hook function executed when delivery of signals is started. More...
 
std::pair< int, SignalActiongetAssociation (uint8_t signalNumber) const
 Gets SignalAction associated with given signal number. More...
 
SignalSet getSignalMask () const
 
int postGenerate (uint8_t signalNumber, ThreadControlBlock &threadControlBlock)
 Part of SignalsReceiverControlBlock::postGenerate() specific to catching unmasked signals. More...
 
std::pair< int, SignalActionsetAssociation (uint8_t signalNumber, const SignalAction &signalAction)
 Sets association for given signal number. More...
 
int setSignalMask (SignalSet signalMask, const SignalsReceiverControlBlock *owner)
 Sets signal mask for associated thread. More...
 
 SignalsCatcherControlBlock (const SignalsCatcherControlBlock &)=delete
 
 SignalsCatcherControlBlock (SignalsCatcherControlBlock &&)=default
 
const SignalsCatcherControlBlockoperator= (const SignalsCatcherControlBlock &)=delete
 
SignalsCatcherControlBlockoperator= (SignalsCatcherControlBlock &&)=delete
 

Private Member Functions

SignalAction clearAssociation (uint8_t signalNumber)
 Clears association for given signal number. More...
 
SignalAction clearAssociation (uint8_t signalNumber, Association &association)
 Clears given association for given signal number. More...
 
AssociationgetAssociationsBegin () const
 
int requestDeliveryOfSignals (ThreadControlBlock &threadControlBlock)
 Requests delivery of signals to associated thread. More...
 

Private Attributes

StorageUniquePointer storageUniquePointer_
 storage for Association objects More...
 
SignalSet signalMask_
 SignalSet with signal mask for associated thread. More...
 
union {
   Association *   associationsEnd_
 pointer to "one past the last" element of range of Association objects More...
 
   Storage *   storageBegin_
 pointer to first element of range of Storage objects More...
 
}; 
 union binds associationsEnd_ and storageBegin_ - these point to the same address More...
 
StoragestorageEnd_
 pointer to "one past the last" element of range of Storage objects More...
 
bool deliveryIsPending_
 true if signal delivery is pending, false otherwise More...
 

Detailed Description

SignalsCatcherControlBlock class is a structure required by threads for "catching" and "handling" of signals.

Member Typedef Documentation

◆ Association

◆ Storage

using distortos::internal::SignalsCatcherControlBlock::Storage = std::aligned_storage<sizeof(Association), alignof(Association)>::type

type of uninitialized storage for Association objects

◆ StorageUniquePointer

unique_ptr (with deleter) to Storage[]

Constructor & Destructor Documentation

◆ SignalsCatcherControlBlock()

distortos::internal::SignalsCatcherControlBlock::SignalsCatcherControlBlock ( StorageUniquePointer &&  storageUniquePointer,
size_t  storageSize 
)

SignalsCatcherControlBlock's constructor.

Parameters
[in]storageUniquePointeris a rvalue reference to StorageUniquePointer with storage for Association objects (sufficiently large for storageSize elements) and appropriate deleter
[in]storageSizeis the number of elements in storage array
Here is the caller graph for this function:

◆ ~SignalsCatcherControlBlock()

distortos::internal::SignalsCatcherControlBlock::~SignalsCatcherControlBlock ( )

Member Function Documentation

◆ clearAssociation() [1/2]

SignalAction distortos::internal::SignalsCatcherControlBlock::clearAssociation ( uint8_t  signalNumber)
private

Clears association for given signal number.

Parameters
[in]signalNumberis the signal for which the association will be cleared, [0; 31]
Returns
SignalAction that was associated with signalNumber, default-constructed object if no association was found
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearAssociation() [2/2]

SignalAction distortos::internal::SignalsCatcherControlBlock::clearAssociation ( uint8_t  signalNumber,
Association association 
)
private

Clears given association for given signal number.

Parameters
[in]signalNumberis the signal for which the association will be cleared, [0; 31]
[in]associationis a reference to Association object from [associationsBegin_; associationsEnd_) range that will be removed
Returns
SignalAction from association

◆ deliveryOfSignalsStartedHook()

void distortos::internal::SignalsCatcherControlBlock::deliveryOfSignalsStartedHook ( )
inline

Hook function executed when delivery of signals is started.

Clears "delivery pending" flag.

Attention
This function should be called only by SignalsReceiverControlBlock::deliveryOfSignalsFinishedHook().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAssociation()

std::pair< int, SignalAction > distortos::internal::SignalsCatcherControlBlock::getAssociation ( uint8_t  signalNumber) const

Gets SignalAction associated with given signal number.

Parameters
[in]signalNumberis the signal for which the association is requested, [0; 31]
Returns
pair with return code (0 on success, error code otherwise) and SignalAction that is associated with signalNumber, default-constructed object if no association was found; error codes:
  • EINVAL - signalNumber value is invalid;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAssociationsBegin()

Association* distortos::internal::SignalsCatcherControlBlock::getAssociationsBegin ( ) const
inlineprivate
Returns
pointer to first element of range of Association objects
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSignalMask()

SignalSet distortos::internal::SignalsCatcherControlBlock::getSignalMask ( ) const
inline
Returns
SignalSet with signal mask for associated thread
Here is the call graph for this function:
Here is the caller graph for this function:

◆ postGenerate()

int distortos::internal::SignalsCatcherControlBlock::postGenerate ( uint8_t  signalNumber,
ThreadControlBlock threadControlBlock 
)

Part of SignalsReceiverControlBlock::postGenerate() specific to catching unmasked signals.

Requests delivery of signals to associated thread if there is some non-default signal handler for the signal.

Parameters
[in]signalNumberis the unmasked signal that was generated, [0; 31]
[in]threadControlBlockis a reference to associated ThreadControlBlock
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ requestDeliveryOfSignals()

int distortos::internal::SignalsCatcherControlBlock::requestDeliveryOfSignals ( ThreadControlBlock threadControlBlock)
private

Requests delivery of signals to associated thread.

Delivery of signals (via special function executed in the associated thread) is requested only if it's not already pending. The thread is unblocked if it was blocked.

Parameters
[in]threadControlBlockis a reference to associated ThreadControlBlock
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAssociation()

std::pair< int, SignalAction > distortos::internal::SignalsCatcherControlBlock::setAssociation ( uint8_t  signalNumber,
const SignalAction signalAction 
)

Sets association for given signal number.

Parameters
[in]signalNumberis the signal for which the association will be set, [0; 31]
[in]signalActionis a reference to SignalAction that will be associated with given signal number, object in internal storage is copy-constructed
Returns
pair with return code (0 on success, error code otherwise) and SignalAction that was associated with signalNumber, default-constructed object if no association was found; error codes:
  • EAGAIN - no resources are available to associate signalNumber with signalAction;
  • EINVAL - signalNumber value is invalid;
Todo:
replace with assertion
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSignalMask()

int distortos::internal::SignalsCatcherControlBlock::setSignalMask ( SignalSet  signalMask,
const SignalsReceiverControlBlock owner 
)

Sets signal mask for associated thread.

If any pending signal is unblocked and owner doesn't equal nullptr, then delivery of signals to associated thread will be requested.

Parameters
[in]signalMaskis the SignalSet with new signal mask for associated thread
[in]ownerselects whether delivery of signals will be requested if any pending signal is unblocked (pointer to owner SignalsReceiverControlBlock object) or not (nullptr)
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ @1

union { ... }

union binds associationsEnd_ and storageBegin_ - these point to the same address

◆ associationsEnd_

Association* distortos::internal::SignalsCatcherControlBlock::associationsEnd_

pointer to "one past the last" element of range of Association objects

◆ deliveryIsPending_

bool distortos::internal::SignalsCatcherControlBlock::deliveryIsPending_
private

true if signal delivery is pending, false otherwise

◆ signalMask_

SignalSet distortos::internal::SignalsCatcherControlBlock::signalMask_
private

SignalSet with signal mask for associated thread.

◆ storageBegin_

Storage* distortos::internal::SignalsCatcherControlBlock::storageBegin_

pointer to first element of range of Storage objects

◆ storageEnd_

Storage* distortos::internal::SignalsCatcherControlBlock::storageEnd_
private

pointer to "one past the last" element of range of Storage objects

◆ storageUniquePointer_

StorageUniquePointer distortos::internal::SignalsCatcherControlBlock::storageUniquePointer_
private

storage for Association objects


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