rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
ThreadController< TStackSize > Class Template Referenceabstract

A base class for a controller that requires its own thread. More...

#include <thread_controller.h>

Inheritance diagram for ThreadController< TStackSize >:
Inheritance graph
[legend]
Collaboration diagram for ThreadController< TStackSize >:
Collaboration graph
[legend]

Public Member Functions

 ThreadController (const char *name, tprio_t priority)
 
void start ()
 Start the thread.
 
void stop ()
 Request thread termination and waits for termination.
 

Protected Member Functions

virtual void ThreadTask ()=0
 
void main () override
 

Protected Attributes

const char *const m_name
 

Private Attributes

const tprio_t m_prio
 
bool m_started = false
 
chibios_rt::ThreadReference ref
 

Detailed Description

template<int TStackSize>
class ThreadController< TStackSize >

A base class for a controller that requires its own thread.

Inherit from ThreadController. Implement ThreadTask with the logic required for your thread. The template parameter specifies the size of the stack used for the thread. (because we have to allocate the stack at compile time, it has to be a template parameter instead of a normal parameter)

Definition at line 18 of file thread_controller.h.

Constructor & Destructor Documentation

◆ ThreadController()

template<int TStackSize>
ThreadController< TStackSize >::ThreadController ( const char name,
tprio_t  priority 
)
inline

Definition at line 39 of file thread_controller.h.

40 : m_prio(priority)
41 , m_name(name)
42 {
43 }
const char *const m_name
const tprio_t m_prio

Member Function Documentation

◆ main()

template<int TStackSize>
void ThreadController< TStackSize >::main ( )
inlineoverrideprotected

Definition at line 30 of file thread_controller.h.

30 {
31 this->setName(m_name);
32
33 ThreadTask();
34 }
virtual void ThreadTask()=0
Here is the call graph for this function:

◆ start()

template<int TStackSize>
void ThreadController< TStackSize >::start ( )
inline

Start the thread.

Definition at line 50 of file thread_controller.h.

51 {
52 if (!m_started)
53 {
54 m_started = true;
55 ref = chibios_rt::BaseStaticThread<TStackSize>::start(m_prio);
56 }
57 }
chibios_rt::ThreadReference ref

Referenced by initUsbMsd().

Here is the caller graph for this function:

◆ stop()

template<int TStackSize>
void ThreadController< TStackSize >::stop ( )
inline

Request thread termination and waits for termination.

Thread should periadicaly execute something like: if (chThdShouldTerminateX()) chThdExit((msg_t)0x0);

Definition at line 66 of file thread_controller.h.

67 {
68 if (m_started) {
69 /* Asking for thread termination.*/
70 ref.requestTerminate();
71
72 /* Waiting for termination, releasing the reference.*/
73 ref.wait();
74
75 m_started = false;
76 }
77 }

◆ ThreadTask()

template<int TStackSize>
virtual void ThreadController< TStackSize >::ThreadTask ( )
protectedpure virtual

Field Documentation

◆ m_name

template<int TStackSize>
const char* const ThreadController< TStackSize >::m_name
protected

◆ m_prio

template<int TStackSize>
const tprio_t ThreadController< TStackSize >::m_prio
private

Definition at line 21 of file thread_controller.h.

Referenced by ThreadController< TStackSize >::start().

◆ m_started

template<int TStackSize>
bool ThreadController< TStackSize >::m_started = false
private

◆ ref

template<int TStackSize>
chibios_rt::ThreadReference ThreadController< TStackSize >::ref
private

The documentation for this class was generated from the following file: