Bare Metal Programming Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Friends | List of all members
bmptk::rtos::flag Class Reference

basic synchronisation mechanism. More...

#include <rtos.h>

Inheritance diagram for bmptk::rtos::flag:
bmptk::rtos::waitable bmptk::rtos::event

Public Member Functions

 flag (task *t, const char *name="")
 constructor, specify onwer and name
 
void set ()
 sets the flag
 
void print (std::ostream &s, bool header=true) const
 prints flag infomation (for debugging)
 
- Public Member Functions inherited from bmptk::rtos::waitable
virtual void clear ()
 clear the waitable
 
- Public Member Functions inherited from bmptk::rtos::event
void print (std::ostream &s, bool header) const
 prints an event, for debugging only
 
bool operator== (const event &rhs) const
 report wether two events are the same
 
bool operator== (const waitable &rhs) const
 report whether an event corresponds to a waitable
 
bool operator!= (const event &rhs) const
 report wether two events are not the same
 
bool operator!= (const waitable &rhs) const
 report whether an event does not correspond to a waitable
 
event operator+ (const event &rhs) const
 add two waitables, result can be used in a wait() call
 

Friends

class event
 
class waitable_set
 
void add (flag *f)
 
void print (std::ostream &stream)
 prints statistics about the tasks to the stream.
 

Additional Inherited Members

- Protected Member Functions inherited from bmptk::rtos::waitable
 waitable (task *task, const char *name)
 constructor, specify owner and name
 
void set ()
 set the waitable
 

Detailed Description

basic synchronisation mechanism.

The basic synchronization mechanism is the (event) flag.

Like all waitables, a flag is created for a particular task. A flag is set by a flag::set() call (or the task::set( flag) call, which has the same effect). Like all waitables, when a task is waiting for a flag (using a task::wait call) and that flag becomes set, the wait call will clear the flag, and return an event that compares equal to the flag. Note that a flag does not count: setting a flag that is already set has no effect on the flag.

A flag must be created for a specific task. The normal place to do this is in the task's constructor. An flag is initially cleared.

The example below shows a led_task that responds to two event flags. The shift flag will cause it to shift the pattern on the LEDs one position to the left, while the invert flag will cause it to invert the pattern. Two addional tasks do nothing but set these flags at fixed intervals. The result is a sort of one-direction Kitt display, which will occasionally flip polarity. Note that in this example the wait call excplicitly mentions the flags it waits for.

TBW flags example

Definition at line 281 of file rtos.h.

Constructor & Destructor Documentation

bmptk::rtos::flag::flag ( task t,
const char *  name = "" 
)

constructor, specify onwer and name

This call creates a timer for task t. The name is used for debugging and statistics.

Member Function Documentation

void bmptk::rtos::flag::set ( )

sets the flag

Setting a flag causes the task that waits for this flag to be awakened.


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