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-04-15 08:32:23 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.14