|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
#include <active_object.hpp>

Public Member Functions | |
| size_t | queuedCount () const noexcept |
| Get the number of operations in the queue. More... | |
| bool | enqueue (TStorageType t) noexcept |
| Add an operation to the queue. More... | |
| void | shutdown () noexcept |
| Shutdown the active object. More... | |
Protected Member Functions | |
| ~activeObject () noexcept | |
| Default destructor. More... | |
Private Types | |
| using | TQueueType = typename std::conditional<(TQueueSize==0), std::queue< TStorageType >, etl::queue< TStorageType, TQueueSize > >::type |
| Queue type definition. More... | |
Private Member Functions | |
| void | thread_handler () noexcept |
| Active object thread function. More... | |
Private Attributes | |
| TQueueType | op_queue_ |
| Queue storage instance. More... | |
| TLock | lock_ |
| Active object lock instance. More... | |
| TCond | cv_ |
| Active object condition variable instance. More... | |
| std::atomic< bool > | shutdown_ = false |
| Flag indicating that the active object should shutdown. More... | |
| std::thread | thread_ = std::thread(&activeObject::thread_handler, this) |
| Active object thread declaration. More... | |
|
private |
Queue type definition.
The queue is statically allocated when TQueueSize > 0, and dynamically allocated when TQueueSize == 0.
|
inlineprotectednoexcept |
Default destructor.
When the active object is destroyed, the thread is shutdown to prevent any race conditions during destruction.
|
inlinenoexcept |
Add an operation to the queue.
This function can be called directly, or by functions internal to the activeObject. For example, the "transfer" API enqueues transfer operations.
This function is marked noexcept because we want the program to terminate if an exception results from this call. For example, the underlying queue may throw on push.
| t | The operation data object to enqueue for later processing. |
Referenced by embvm::i2c::activeMaster< 128 >::transfer_(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::transfer_().
|
inlinenoexcept |
Get the number of operations in the queue.
|
inlinenoexcept |
Shutdown the active object.
Call this function in the parent class destructor to stop the AO thread operation before destroying the parent class. This will prevent memory access problems due to race conidtions during destruction.
This function is marked noexcept because we want the program to terminate if an exception results from this call.
The shutdown process is permanent and cannot be reversed without recreating the object.
Referenced by embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::~activeObject().
|
inlineprivatenoexcept |
Active object thread function.
This function monitors the queue and sleeps until new operations are added (or shutdown_ is set). Once a new item is added to the queue, the thread wakes, pops the op off the queue, and calls the derived class's process_() function.
This function is marked noexcept because we want the program to terminate if an exception results from this call. The underlying queue may throw on pop, for instance.
|
private |
Active object condition variable instance.
Referenced by embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::enqueue(), embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::shutdown(), and embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::thread_handler().
|
private |
Active object lock instance.
Referenced by embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::enqueue(), embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::shutdown(), and embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::thread_handler().
|
private |
Queue storage instance.
Referenced by embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::enqueue(), embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::queuedCount(), and embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::thread_handler().
|
private |
Flag indicating that the active object should shutdown.
Referenced by embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::shutdown(), embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::thread_handler(), and embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::~activeObject().
|
private |
Active object thread declaration.
Referenced by embutil::activeObject< aardvarkI2CMaster, std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > >::shutdown().
1.8.15