Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2024 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : /**
12 : * \ingroup async
13 : */
14 : #pragma once
15 :
16 : namespace async
17 : {
18 : /**
19 : * This is a template class that acts as collection (linked list)
20 : * of Tasks to be added to the FreeRTOS system.
21 : *
22 : * \tparam T The underlying implementing execute function.
23 : */
24 :
25 : template<class T>
26 : class StaticRunnable
27 : {
28 : protected:
29 : ~StaticRunnable() = default;
30 :
31 : public:
32 : StaticRunnable();
33 :
34 : static void run();
35 :
36 : private:
37 : T* _next;
38 :
39 : static T* _first;
40 : };
41 :
42 : template<class T>
43 : T* StaticRunnable<T>::_first = nullptr;
44 :
45 : /**
46 : * Class constructor.
47 : * On instance construction the new instance is added into
48 : * the inked list by adjusting the pointers _first and _next.
49 : */
50 : template<class T>
51 20 : StaticRunnable<T>::StaticRunnable() : _next(_first)
52 : {
53 20 : _first = static_cast<T*>(this);
54 20 : }
55 :
56 : template<class T>
57 20 : void StaticRunnable<T>::run()
58 : {
59 40 : while (_first != nullptr)
60 : {
61 20 : T* const current = _first;
62 20 : _first = _first->_next;
63 20 : current->execute();
64 : }
65 20 : }
66 :
67 : } // namespace async
|