LCOV - code coverage report
Current view: top level - asyncFreeRtos/include/async - StaticRunnable.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 8 100.0 %
Date: 2025-01-20 13:53:09 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : /**
       4             :  * \ingroup async
       5             :  */
       6             : #ifndef GUARD_DACDF931_AF72_4275_BB52_C84A579EB25F
       7             : #define GUARD_DACDF931_AF72_4275_BB52_C84A579EB25F
       8             : 
       9             : #include "estd/functional.h"
      10             : #include "estd/slice.h"
      11             : 
      12             : namespace async
      13             : {
      14             : /**
      15             :  * This is a template class that acts as collecion (linked list)
      16             :  * of Tasks to be added to the FreeRTOS system.
      17             :  *
      18             :  * \tparam T The underlying implementing execute function.
      19             :  */
      20             : 
      21             : template<class T>
      22             : class StaticRunnable
      23             : {
      24             : protected:
      25             :     ~StaticRunnable() = default;
      26             : 
      27             : public:
      28             :     StaticRunnable();
      29             : 
      30             :     static void run();
      31             : 
      32             : private:
      33             :     T* _next;
      34             : 
      35             :     static T* _first;
      36             : };
      37             : 
      38             : template<class T>
      39             : T* StaticRunnable<T>::_first = nullptr;
      40             : 
      41             : /**
      42             :  * Class constructor.
      43             :  * On instance construction the new instance is added into
      44             :  * the inked list by adjusting the pointers _first and _next.
      45             :  */
      46             : template<class T>
      47          18 : StaticRunnable<T>::StaticRunnable() : _next(_first)
      48             : {
      49          18 :     _first = static_cast<T*>(this);
      50             : }
      51             : 
      52             : template<class T>
      53          17 : void StaticRunnable<T>::run()
      54             : {
      55          19 :     while (_first != nullptr)
      56             :     {
      57          18 :         T* const current = _first;
      58          18 :         _first           = _first->_next;
      59          33 :         current->execute();
      60             :     }
      61          17 : }
      62             : 
      63             : } // namespace async
      64             : 
      65             : #endif // GUARD_DACDF931_AF72_4275_BB52_C84A579EB25F

Generated by: LCOV version 1.14