distortos  v0.7.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 "distortos/internal/synchronization/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 afterGenerateQueueUnlocked (ThreadControlBlock &threadControlBlock)
 Part of SignalsReceiverControlBlock::afterGenerateQueueUnlocked() specific to catching unmasked signals. More...
 
int beforeGenerateQueue (ThreadControlBlock &threadControlBlock)
 Part of SignalsReceiverControlBlock::beforeGenerateQueue() specific to catching unmasked signals. 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
 
std::pair< int, SignalActionsetAssociation (uint8_t signalNumber, const SignalAction &signalAction)
 Sets association for given signal number. More...
 
void 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

◆ ~SignalsCatcherControlBlock()

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

Member Function Documentation

◆ afterGenerateQueueUnlocked()

void distortos::internal::SignalsCatcherControlBlock::afterGenerateQueueUnlocked ( ThreadControlBlock threadControlBlock)

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

This function does nothing if the request is for non-current thread of execution. Otherwise it delivers signals to current thread.

Note
It is assumed that some unmasked signal with non-default signal handler is pending.
Parameters
[in]threadControlBlockis a reference to associated ThreadControlBlock
Here is the call graph for this function:
Here is the caller graph for this function:

◆ beforeGenerateQueue()

int distortos::internal::SignalsCatcherControlBlock::beforeGenerateQueue ( ThreadControlBlock threadControlBlock)

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

This function does nothing if the request is for current thread of execution. Otherwise it requests delivery of signals to associated thread.

Note
It is assumed that some unmasked signal with non-default signal handler will be pending before leaving critical section.
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:

◆ 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 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 caller graph for this function:

◆ getSignalMask()

SignalSet distortos::internal::SignalsCatcherControlBlock::getSignalMask ( ) const
inline
Returns
SignalSet with signal mask for associated thread
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;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSignalMask()

void 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 pending and unblocked signals will be delivered.

Parameters
[in]signalMaskis the SignalSet with new signal mask for associated thread
[in]ownerselects whether pending and unblocked signals will be delivered (pointer to owner SignalsReceiverControlBlock object) or not (nullptr)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ @17

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: