#include <mn_convar_task.hpp>

+ Inheritance diagram for mn::ext::basic_convar_task:
+ Collaboration diagram for mn::ext::basic_convar_task:

Public Member Functions

 basic_convar_task ()
 
 basic_convar_task (std::string strName, basic_task::priority uiPriority, unsigned short usStackDepth=MN_THREAD_CONFIG_MINIMAL_STACK_SIZE)
 
virtual void signal ()
 
virtual int wait (convar_t &cv, mutex_t &cvl, TickType_t timeOut=portMAX_DELAY)
 
- Public Member Functions inherited from mn::basic_task
 basic_task () noexcept
 
 basic_task (std::string strName, basic_task::priority uiPriority=basic_task::priority::Normal, unsigned short usStackDepth=MN_THREAD_CONFIG_MINIMAL_STACK_SIZE) noexcept
 
virtual ~basic_task ()
 Our destructor. Delete the task. More...
 
virtual int start (int uiCore=MN_THREAD_CONFIG_DEFAULT_CORE)
 Create and starts the Task. More...
 
int kill ()
 Destroy and delete the task and call the function 'on_kill'. More...
 
bool is_running ()
 Is the Task running? More...
 
std::string get_name ()
 Get the debug name of this task. More...
 
basic_task::priority get_priority ()
 Get the priority of this task. More...
 
unsigned short get_stackdepth ()
 Get the stack depth of this task. More...
 
xTaskHandle get_handle ()
 Accessor to get the task's backing task handle. There is no setter, on purpose. More...
 
int get_return_value ()
 Get the return value of this task - after run. More...
 
timespan_t get_time_since_start () const
 Get the time since start of this task. More...
 
int32_t get_id ()
 Get the FreeRTOS task Numberid of this task. More...
 
int32_t get_on_core ()
 Get the core number of this task run. More...
 
void set_priority (basic_task::priority uiPriority)
 Set the priority of this task. More...
 
void suspend ()
 Suspend this task. More...
 
void resume ()
 Resume a specific task. More...
 
bool joinable () const noexcept
 
int join (unsigned int xTickTimeout=portMAX_DELAY)
 join the task, Wait in other task to end this task. More...
 
int join (timespan_t time)
 join the task, Wait in other task to end this task. More...
 
int wait (unsigned int xTimeOut)
 Wait for start the task. More...
 
int wait (timespan_t time)
 Wait for start the task. More...
 
virtual void on_start ()
 This virtual function call on creating, use for user code It is optional whether you implement this or not. More...
 
virtual void on_kill ()
 This virtual function call on kill, use for user code It is optional whether you implement this or not. More...
 
virtual int on_task ()
 Implementation of your actual task code. You must override this function. More...
 
virtual void on_cleanup ()
 Called on exit from your on_task() routine. More...
 
state get_state ()
 Get the state of the task. More...
 
 operator xTaskHandle ()
 Operator to get the task's backing task handle. More...
 
 operator int ()
 Operator to get the ID assigned to the task. More...
 
bool operator== (const basic_task &r) const
 
bool operator!= (const basic_task &r) const
 
bool operator< (const basic_task &r) const
 
bool operator> (const basic_task &r) const
 

Protected Member Functions

virtual void on_signal ()
 

Private Attributes

binary_semaphore_t m_waitSem
 

Friends

class basic_condition_variable
 

Additional Inherited Members

- Public Types inherited from mn::basic_task
enum class  priority {
  Idle = MN_THREAD_CONFIG_CORE_PRIORITY_IDLE , Low = MN_THREAD_CONFIG_CORE_PRIORITY_LOW , Normal = MN_THREAD_CONFIG_CORE_PRIORITY_NORM , HalfCritical = MN_THREAD_CONFIG_CORE_PRIORITY_HALFCRT ,
  Urgent = MN_THREAD_CONFIG_CORE_PRIORITY_URGENT , Critical = MN_THREAD_CONFIG_CORE_PRIORITY_CRITICAL
}
 Task priority. More...
 
enum class  state {
  Running = 0 , Ready , Blocked , Suspended ,
  Deleted
}
 
using native_handle_type = xTaskHandle
 
- Static Public Member Functions inherited from mn::basic_task
static void suspend (basic_task *t)
 Suspend the given task. More...
 
static void resume (basic_task *t)
 Resume the given task. More...
 
static void yield ()
 Yield the scheduler. More...
 
static void sleep (unsigned int secs)
 sleep this task for n seconds More...
 
static void usleep (unsigned int usec)
 sleep this task for n micro seconds More...
 
static void nsleep (const timespan_t &req, timespan_t *rem)
 pause execution for a specified time More...
 
static uint32_t get_tasks ()
 Get current number of tasks. More...
 
static bool is_current (basic_task *task)
 Is the given task the current running task ? More...
 
static basic_taskget_self ()
 Get the current task. More...
 
- Static Protected Member Functions inherited from mn::basic_task
static void runtaskstub (void *parm)
 Adapter function that allows you to write a class specific on_task() function that interfaces with FreeRTOS. More...
 
- Protected Attributes inherited from mn::basic_task
LockType_t m_runningMutex
 Lock Objekt for task safty. More...
 
LockType_t m_contextMutext
 
LockType_t m_continuemutex
 
std::string m_strName
 The name of this task. More...
 
basic_task::priority m_uiPriority
 A saved / cached copy of what the task's priority is. More...
 
unsigned short m_usStackDepth
 Stack depth of this task, in words. More...
 
int m_retval
 The return value from user task routine. More...
 
bool m_bRunning
 Flag whether or not the task was started. More...
 
int32_t m_iID
 The FreeRTOS task Number. More...
 
int32_t m_iCore
 A saved / cached copy of which core this task is running on. More...
 
native_handle_type m_pHandle
 Reference to the underlying task handle for this task. More...
 
event_group_t m_eventGroup
 

Detailed Description

Extension of the basic thread with condition variable support

Constructor & Destructor Documentation

◆ basic_convar_task() [1/2]

mn::ext::basic_convar_task::basic_convar_task ( )

◆ basic_convar_task() [2/2]

mn::ext::basic_convar_task::basic_convar_task ( std::string  strName,
basic_task::priority  uiPriority,
unsigned short  usStackDepth = MN_THREAD_CONFIG_MINIMAL_STACK_SIZE 
)

Constructor to create a named thread.

Parameters
strNameName of the thread. Only useful for debugging.
uiPriorityFreeRTOS priority of this Thread.
usStackDepthNumber of "words" allocated for the Thread stack. default configMINIMAL_STACK_SIZE

Member Function Documentation

◆ on_signal()

virtual void mn::ext::basic_convar_task::on_signal ( )
inlineprotectedvirtual

Call on signal functions

◆ signal()

void mn::ext::basic_convar_task::signal ( )
virtual

helper function to signal this thread.

◆ wait()

int mn::ext::basic_convar_task::wait ( convar_t cv,
mutex_t cvl,
TickType_t  timeOut = portMAX_DELAY 
)
virtual

Have this thread wait on a condition variable.

Note
Threads wait, while condition_variables signal.
Parameters
cvThe condition variable associated with the Wait.
cvlThe required condition variable lock. The Lock must be held before calling Wait.
timeOutAllows you to specify a timeout on the Wait, if desired.
Returns

Friends And Related Function Documentation

◆ basic_condition_variable

friend class basic_condition_variable
friend

The Thread class and the basic_condition_variable class are interdependent. If we allow the basic_condition_variable class to access the internals of the basic_convar_task class, we can reduce the public interface, which is a good thing.

Member Data Documentation

◆ m_waitSem

binary_semaphore_t mn::ext::basic_convar_task::m_waitSem
private

How we wait and signal the thread when using condition variables. Because a semaphore maintains state, this solves the race condition between dropping the CvLock and waiting.


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