|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
Queues for storing function objects. More...
|
Classes | |
| class | embutil::FuncOp |
| Base Class for storing functions. More... | |
| class | embutil::FuncOpBound< TFuncOp > |
| Represents a bound function object. More... | |
| class | embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc > |
| Static-memory function queue that accepts functors of multiple sizes. More... | |
Queues for storing function objects.
Users should utilize the embutil::StaticFunctionQueue or embutil::DynamicFunctionQueue template specializations. Other type definitions are used to make the queue work properly.
| class embutil::FuncOp |
Base Class for storing functions.
This base class represents a function operation stored in the function queue.
In order to support functors of different sizes in a single statically-allocated function queue, we need to provide a common interface for each size.
A functor is stored in multiple blocks of FuncOp objects. The derived class, FuncOpBound, overloads exec() to call the bound operation.

Public Member Functions | |
| virtual | ~FuncOp () |
| Default destructor. More... | |
| virtual void | exec () |
| Invoke the function. More... | |
| void | operator() () |
| operator() invokes the function. More... | |
|
virtualdefault |
Default destructor.
|
inlinevirtual |
Invoke the function.
Base class invocation does nothing. Derived FuncOpBound classes overload this for the actual execution.
Reimplemented in embutil::FuncOpBound< TFuncOp >.
Referenced by operator()().
|
inline |
operator() invokes the function.
References exec().
| class embutil::FuncOpBound |
Represents a bound function object.
A bound function object takes in an operation of any type and stores it as a private member. Since our queue is intended to support objects of different sizes, we decay to the FuncOp base class interface for managing the queue.
| TFuncOp | The function prototype to store in the bound object. |

Public Member Functions | |
| FuncOpBound (const TFuncOp &op) | |
| Construct the FuncOpBound object with an operation. More... | |
| FuncOpBound (TFuncOp &&op) | |
| Construct the FuncOpBound object with an operation. More... | |
| ~FuncOpBound () final=default | |
| Default destructor. More... | |
| void | exec () final |
| Invoke the bound operation. More... | |
| void | operator() () |
| operator() invokes the function. More... | |
Private Attributes | |
| TFuncOp | op_ |
| The bound functor. More... | |
|
inlineexplicit |
Construct the FuncOpBound object with an operation.
| op | The operation to bind. Can be any functor. |
|
inlineexplicit |
Construct the FuncOpBound object with an operation.
| op | The operation to bind. Can be any functor. |
|
finaldefault |
Default destructor.
|
inlinefinalvirtual |
Invoke the bound operation.
Reimplemented from embutil::FuncOp.
References embutil::FuncOpBound< TFuncOp >::op_.
|
inlineinherited |
operator() invokes the function.
References embutil::FuncOp::exec().
|
private |
The bound functor.
Referenced by embutil::FuncOpBound< TFuncOp >::exec().
| class embutil::StaticFunctionQueue |
Static-memory function queue that accepts functors of multiple sizes.
This class stores function objects of varying sizes in a single queue. If you were to manage a queue of stdext::inplace_function, you would have to increase the size of each element to accommodate the largest possible size. This is inefficient. Instead, we support varying sizes by using more complicated memory management.
If you want a dynamic memory alternative, use std::queue<std::function>.
This class is intended to be used with functions of type void(void). You can store functions with arguments in the queue, but you must use a std::bind expression to reduce the arguments.
Functors can be pushed to the queue using push(). This API creates a FuncOpBound object and stores the element for future processing.
Elements can be removed from the queue using front(). A std::unique_ptr is returned, ensuring that the memory will be returned to the function queue's pool once the caller is done with the function. This means that front() can only be called once per queue element - there is no peeking. pop() can then be called to remove the element from the front of the queue.
Invoking the function after pop() ensures two things:
Here is an example flow for removing elements from the function queue:
If a single thread is managing the queue, popAndExec() can be used to remove the function from the queue and execute it.
| TFunc | The functor storage type, such as std::function or stdext::inplace_function. |
| TQueueElements | The number of elements to store in the queue. TQueueElements must be > 0. |
| TLargestSize | The size of the largest expected allocation, in bytes. |
(TQueueElements * TLargestSize). Public Member Functions | |
| StaticFunctionQueue ()=default | |
| Default constructor. More... | |
| ~StaticFunctionQueue ()=default | |
| Default destructor. More... | |
| StaticFunctionQueue (const StaticFunctionQueue &)=delete | |
| Deleted copy constructor. More... | |
| const StaticFunctionQueue & | operator= (const StaticFunctionQueue &)=delete |
| Deleted copy assignment operator. More... | |
| StaticFunctionQueue (StaticFunctionQueue &&)=delete | |
| Deleted move constructor. More... | |
| StaticFunctionQueue & | operator= (StaticFunctionQueue &&)=delete |
| Deleted move assignment operator. More... | |
| template<typename TFuncOp > | |
| void | push (const TFuncOp &op) noexcept |
| Add a function to the queue. More... | |
| template<typename TFuncOp > | |
| void | push (TFuncOp &&op) noexcept |
| void | popAndExec () noexcept |
| Remove the next functor from the front of the queue and execute it. More... | |
| auto | front () noexcept |
| Get a copy of the functor at the front of the queue. More... | |
| void | pop () noexcept |
| Remove the element at the front of the queue. More... | |
| bool | empty () const noexcept |
| Check if the queue is empty. More... | |
| size_t | size () const noexcept |
| Check the current number of elements in the queue. More... | |
| constexpr size_t | capacity () const noexcept |
| Get the capacity in elements. More... | |
| constexpr size_t | capacity_bytes () const noexcept |
| Get the total memory consumed by this queue in bytes. More... | |
Private Types | |
| using | UniqueElementPtr_t = typename std::unique_ptr< FuncOp, stdext::inplace_function< void(FuncOp *), 3 *sizeof(void *)> > |
| Convenience alias for the unique pointer to the element We return functors to the client as a std::unique_ptr<FuncOp>. More... | |
| using | ElementPtr_t = FuncOp * |
| Alias for our element. More... | |
| using | FuncOpStorage_t = etl::queue< ElementPtr_t, TQueueElements > |
| Alias for the element storage queue. More... | |
Private Member Functions | |
| void | deleter (FuncOp *ptr) |
| Return FuncOp objects to the memory pool. More... | |
Private Attributes | |
| etl::generic_pool< TLargestSize, etl::largest< FuncOp, TFunc >::alignment, TQueueElements > | mem_pool_ |
| Memory storage for FuncElement types We utilize a memory pool to allocate FuncOpBound objects for storage. More... | |
| FuncOpStorage_t | queue_ |
| Queue which stores function objects. More... | |
|
private |
Alias for our element.
We store pointers to FuncOp objects.
|
private |
Alias for the element storage queue.
|
private |
Convenience alias for the unique pointer to the element We return functors to the client as a std::unique_ptr<FuncOp>.
Memory is allocated from mem_pool_, so we use a deleter to ensure memory is recovered.
|
default |
Default constructor.
|
default |
Default destructor.
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlinenoexcept |
Get the capacity in elements.
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
|
inlinenoexcept |
Get the total memory consumed by this queue in bytes.
|
inlineprivate |
Return FuncOp objects to the memory pool.
This deleter is used by with the std::unique_ptr that is used to store the function elements. When the FuncOp object goes out of scope, its memory is automatically returned to the pool.
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::mem_pool_.
Referenced by embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::front(), and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::popAndExec().
|
inlinenoexcept |
Check if the queue is empty.
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::size().
|
inlinenoexcept |
Get a copy of the functor at the front of the queue.
For efficient queue usage, clients will want to get the element from the front of the queue, call pop() to remove it from the queue, and then execute the function. This flow will ensure that the queue is not locked while the function is running (which happens with popAndExec()).
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::deleter(), and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
|
delete |
Deleted copy assignment operator.
|
delete |
Deleted move assignment operator.
|
inlinenoexcept |
Remove the element at the front of the queue.
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
|
inlinenoexcept |
Remove the next functor from the front of the queue and execute it.
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::deleter(), and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
|
inlinenoexcept |
Add a function to the queue.
This function is noexcept because we want our program to abort if we are out of memory. Depending on the underlying queue type, it is certainly likely that there is throw support.
| TFuncOp | The type of the functor to add to the queue. This template parameter is automatically deduced by the compiler. |
| op | The functor object to add to the queue. |
References assert, embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::mem_pool_, and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References assert, embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::mem_pool_, and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
|
inlinenoexcept |
Check the current number of elements in the queue.
References embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::queue_.
Referenced by embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::empty().
|
private |
Memory storage for FuncElement types We utilize a memory pool to allocate FuncOpBound objects for storage.
Referenced by embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::deleter(), and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::push().
|
private |
Queue which stores function objects.
Referenced by embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::capacity(), embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::front(), embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::pop(), embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::popAndExec(), embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::push(), and embutil::StaticFunctionQueue< TQueueElements, TLargestSize, TFunc >::size().
1.8.15