Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
OSThread Class Reference

This class provides a threading API. More...

#include <OS.hxx>

Inheritance diagram for OSThread:
SN74HC595< N > ExecutorBase FdHubPortBase::ReadThreadBase MCP2515Can MagSensorTest PCA9685PWM SN74HC595< N > TCAN4550Can TCAN4550Can TinyUsbCdc::UsbDeviceThread

Classes

struct  ScopedSetThreadHandle
 Helper class for using lock_to_thread. More...
 

Public Member Functions

 OSThread (const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
 Create a thread.
 
 OSThread ()
 Creates a thread via inheritance.
 
void start (const char *name, int priority, size_t stack_size)
 Starts the thread.
 
virtual ~OSThread ()
 Default destructor.
 
bool is_created ()
 
void inherit ()
 Inherits the current thread.
 
os_thread_t get_handle ()
 
void lock_to_thread ()
 Sets the thread handle to the current calling thread's.
 
void unlock_from_thread ()
 Resets the thread handle to none.
 

Static Public Member Functions

static int getpriority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority_min ()
 Get the minimum thread priority.
 
static int get_priority_max ()
 Get the maximum thread priority.
 

Protected Member Functions

virtual void * entry ()
 User entry point for the created thread.
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (OSThread)
 

Static Private Member Functions

static void * start (void *arg)
 Starting point for a new thread.
 

Private Attributes

os_thread_t handle
 Private thread handle.
 

Detailed Description

This class provides a threading API.

Definition at line 45 of file OS.hxx.

Constructor & Destructor Documentation

◆ OSThread() [1/2]

OSThread::OSThread ( const char *  name,
int  priority,
size_t  stack_size,
void *(*)(void *)  start_routine,
void *  arg 
)
inline

Create a thread.

Parameters
namename of thread, NULL for an auto generated name
prioritypriority of created thread, 0 means default, lower numbers means lower priority, higher numbers mean higher priority
stack_sizesize in bytes of the created thread's stack
start_routineentry point of the thread
argentry parameter to the thread

Definition at line 57 of file OS.hxx.

◆ OSThread() [2/2]

OSThread::OSThread ( )
inline

Creates a thread via inheritance.

The user must overload the entry() function and call the start() method whenever convenient.

Definition at line 65 of file OS.hxx.

◆ ~OSThread()

virtual OSThread::~OSThread ( )
inlinevirtual

Default destructor.

Definition at line 85 of file OS.hxx.

Member Function Documentation

◆ entry()

virtual void * OSThread::entry ( )
inlineprotectedvirtual

User entry point for the created thread.

Returns
exit status

Reimplemented in ExecutorBase, TCAN4550Can, MCP2515Can, PCA9685PWM, SN74HC595< N >, SN74HC595< N >, TCAN4550Can, MagSensorTest, TinyUsbCdc::UsbDeviceThread, and FdHubPortBase::ReadThreadBase.

Definition at line 179 of file OS.hxx.

◆ get_handle()

os_thread_t OSThread::get_handle ( )
inline
Returns
the thread handle for os_xxx operations.

Definition at line 138 of file OS.hxx.

◆ get_priority()

static int OSThread::get_priority ( OSThread thread)
inlinestatic

Return the current thread priority.

Parameters
threadhandle to thread of interest
Returns
current thread priority

Definition at line 116 of file OS.hxx.

◆ get_priority_max()

static int OSThread::get_priority_max ( )
inlinestatic

Get the maximum thread priority.

Returns
maximum trhead priority

Definition at line 132 of file OS.hxx.

◆ get_priority_min()

static int OSThread::get_priority_min ( )
inlinestatic

Get the minimum thread priority.

Returns
minimum trhead priority

Definition at line 124 of file OS.hxx.

◆ getpriority()

static int OSThread::getpriority ( OSThread thread)
inlinestatic

Return the current thread priority.

Depricated, use get_priority().

Parameters
threadhandle to thread of interest
Returns
current thread priority

Definition at line 107 of file OS.hxx.

◆ inherit()

void OSThread::inherit ( )
inline

Inherits the current thread.

Definition at line 96 of file OS.hxx.

◆ is_created()

bool OSThread::is_created ( )
inline
Returns
true if a thread was already created.

Definition at line 90 of file OS.hxx.

◆ lock_to_thread()

void OSThread::lock_to_thread ( )
inline

Sets the thread handle to the current calling thread's.

Needed for multiplexing environments like Arduino.

Definition at line 145 of file OS.hxx.

◆ start() [1/2]

void OSThread::start ( const char *  name,
int  priority,
size_t  stack_size 
)
inline

Starts the thread.

This call can be used when OSThread is inherited and there is a virtual entry point.

Parameters
namename of thread, NULL for an auto generated name
prioritypriority of created thread, 0 means default, lower numbers means lower priority, higher numbers mean higher priority
stack_sizesize in bytes of the created thread's stack

Definition at line 78 of file OS.hxx.

◆ start() [2/2]

static void * OSThread::start ( void *  arg)
inlinestaticprivate

Starting point for a new thread.

Parameters
argpointer to an OSThread instance
Returns
exit status

Definition at line 191 of file OS.hxx.

◆ unlock_from_thread()

void OSThread::unlock_from_thread ( )
inline

Resets the thread handle to none.

Definition at line 152 of file OS.hxx.

Member Data Documentation

◆ handle

os_thread_t OSThread::handle
private

Private thread handle.

Definition at line 200 of file OS.hxx.


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