COSA
An Object-Oriented Platform for Arduino Programming
Nucleo::Thread Class Reference

#include <Thread.hh>

Inheritance diagram for Nucleo::Thread:
Inheritance graph
Collaboration diagram for Nucleo::Thread:
Collaboration graph

Public Member Functions

virtual void run ()
 
void resume (Thread *thread)
 
void yield ()
 
void delay (uint32_t ms)
 
void enqueue (Head *queue, Thread *thread=NULL)
 
void dequeue (Head *queue, bool flag=true)
 
void detach ()
 
Linkagesucc () const
 
Linkagepred () const
 
void attach (Linkage *pred)
 
virtual void on_event (uint8_t type, uint16_t value)
 

Static Public Member Functions

static Threadrunning ()
 
static void begin (Thread *thread=NULL, size_t size=0)
 
static void service ()
 

Protected Member Functions

void init (void *stack)
 

Protected Attributes

jmp_buf m_context
 
uint32_t m_expires
 
Linkagem_succ
 
Linkagem_pred
 

Static Protected Attributes

static const size_t MAIN_STACK_MAX = 64
 
static Head s_delayed
 
static Thread s_main
 
static Threads_running = &s_main
 
static size_t s_top = MAIN_STACK_MAX
 

Friends

class Semaphore
 

Detailed Description

The Cosa Nucleo Thread; run-to-completion multi-tasking.

Definition at line 33 of file Thread.hh.

Member Function Documentation

void Linkage::attach ( Linkage pred)
inlineinherited

Attach given linkage as predecessor. Will check and detach if already attached.

Parameters
[in]predlinkage to attach.
Note
atomic

Definition at line 71 of file Linkage.hh.

void Thread::begin ( Thread thread = NULL,
size_t  size = 0 
)
static

Schedule static thread with given stack size. Using the default parameters will start the main thread.

Parameters
[in]threadto initiate and schedule.
[in]sizeof stack.

Definition at line 57 of file Thread.cpp.

void Thread::delay ( uint32_t  ms)

Delay at least the given time period in milli-seconds. The resolution is determined by the Watchdog clock and has a resolution of 16 milli-seconds (per tick). The actual delay also depends on how other threads yield.

Parameters
[in]msminimum delay time period in milli-seconds.

Definition at line 121 of file Thread.cpp.

void Thread::dequeue ( Head queue,
bool  flag = true 
)

If given queue is not empty dequeue first thread and resume direct if flag is true otherwise enqueue first in run queue.

Parameters
[in]queueto transfer from.
[in]flagresume direct otherwise on yield (Default true).

Definition at line 107 of file Thread.cpp.

void Link::detach ( )
inlineinherited

Detach this link. Unlink from any list.

Definition at line 125 of file Linkage.hh.

void Thread::enqueue ( Head queue,
Thread thread = NULL 
)

Enqueue running thread to given queue and yield.

Parameters
[in]queueto transfer to.
[in]threadto resume (Default yield).

Definition at line 98 of file Thread.cpp.

void Thread::init ( void *  stack)
protected

Initiate thread and prepare for initial call to virtual member function run(). Stack frame is allocated by begin().

Parameters
[in]stacktop pointer.

Definition at line 49 of file Thread.cpp.

virtual void Event::Handler::on_event ( uint8_t  type,
uint16_t  value 
)
inlinevirtualinherited

Default null event handler. Should be redefined by sub-classes. Called by Event::dispatch().

Parameters
[in]typethe event type.
[in]valuethe event value.

Reimplemented in Menu::RotaryController, Rotary::Dial< T >, AnalogPin, Job, TWI::Slave, ProtoThread, AnalogPins, and Periodic.

Definition at line 107 of file Event.hh.

Linkage* Linkage::pred ( ) const
inlineinherited

Return predecessor in sequence.

Returns
predecessor linkage.

Definition at line 60 of file Linkage.hh.

void Thread::resume ( Thread thread)

Yield control to the given thread. Preserve stack and machine state and later continue.

Parameters
[in]threadto resume.

Definition at line 90 of file Thread.cpp.

void Thread::run ( )
virtual

The thread main function. The function is called when the thread is scheduled and becomes running. Normally the function is an end-less loop. Returning from the function will result in that the function is called again. The default implementation is the main thread. It is responsible for power down when there are no other active threads. Other threads must override this member function.

Definition at line 72 of file Thread.cpp.

static Thread* Nucleo::Thread::running ( )
inlinestatic

Return running thread.

Returns
thread.

Definition at line 39 of file Thread.hh.

void Thread::service ( )
static

Service the nucleos main thread. Should be called in the loop() function.

Definition at line 133 of file Thread.cpp.

Linkage* Linkage::succ ( ) const
inlineinherited

Return successor in sequence.

Returns
successor linkage.

Definition at line 51 of file Linkage.hh.

void Nucleo::Thread::yield ( )
inline

Yield control to the next thread in the thread queue. Preserve stack and machine state and later continue.

Definition at line 75 of file Thread.hh.

Friends And Related Function Documentation

friend class Semaphore
friend

Allow friends to use the queue member functions.

Definition at line 143 of file Thread.hh.

Member Data Documentation

jmp_buf Nucleo::Thread::m_context
protected

Thread context.

Definition at line 130 of file Thread.hh.

uint32_t Nucleo::Thread::m_expires
protected

Delay time expires; should not run for more than 2**32 seconds.

Definition at line 133 of file Thread.hh.

Linkage* Linkage::m_pred
protectedinherited

Definition at line 94 of file Linkage.hh.

Linkage* Linkage::m_succ
protectedinherited

Double linked list pointers.

Definition at line 93 of file Linkage.hh.

const size_t Nucleo::Thread::MAIN_STACK_MAX = 64
staticprotected

Size of main thread stack.

Definition at line 115 of file Thread.hh.

Head Thread::s_delayed
staticprotected

Queue for delayed threads.

Definition at line 118 of file Thread.hh.

Thread Thread::s_main
staticprotected

Main thread and thread queue head.

Definition at line 121 of file Thread.hh.

Thread * Thread::s_running = &s_main
staticprotected

Running thread.

Definition at line 124 of file Thread.hh.

size_t Thread::s_top = MAIN_STACK_MAX
staticprotected

Top of stack allocation.

Definition at line 127 of file Thread.hh.


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