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

synchronous handling over of a data item More...

#include <rtos.h>

Inheritance diagram for bmptk::rtos::mailbox< T >:

Public Member Functions

 mailbox (const char *name="")
 constructor, specify mailbox name
 
void write (const T item)
 write an item into the mailbox
 
read (void)
 read a value from the mailbox
 

Detailed Description

template<class T>
class bmptk::rtos::mailbox< T >

synchronous handling over of a data item

A mailbox is a template class synchronization mechanism. A single value can be written to the mailbox. Another task can read the value from the mailbox. The read and write calls each wait on each other before they are allowed to proceed. A mailbox is not created for a particular task, and it is not a waitable.

Initially a mailbox is empty. The write() operation bloks the calling task until the mailbox is empty, then writes to the mailbox, and blocks. The read() operation blocks the calling task until there is a value in the mailbox. Then it reads the value, unblocks the task that wrote to the mailbox, and returns.

The example below uses a mailbox to buffer writing cout data to the UART. The function that writes each cout character writes it to a mailbox, which is read by the UART task. This task waits 2 MS after each write to the UART, to avoid busy waiting.

TBW

Definition at line 1090 of file rtos.h.

Constructor & Destructor Documentation

template<class T >
bmptk::rtos::mailbox< T >::mailbox ( const char *  name = "")
inline

constructor, specify mailbox name

Create a mutex. The mutex is initially set. The name is used for debugging and statistics.

The template argument T must be a class that has a non-arguments constructor and supports assignment.

Definition at line 1100 of file rtos.h.

Member Function Documentation

template<class T >
T bmptk::rtos::mailbox< T >::read ( void  )
inline

read a value from the mailbox

If one or more tasks are waiting for the mutex the first one is released, and it now owns the mutex. Otherwise, if the mutex is cleared it is now set.

It is an error for a task to call signal() on a mutex that it does not own (that it did not call wait() on). After the signal the task no longer owns the mutex.

Definition at line 1133 of file rtos.h.

template<class T >
void bmptk::rtos::mailbox< T >::write ( const T  item)
inline

write an item into the mailbox

If the mutex was set it it is now cleared, and the calling task owns the mutex.

Otherwise the current task waits (is halted) until the owning task calls signal() on the same mutex. The signal() calls will release the tasks in the order of their wait() calls.

Definition at line 1111 of file rtos.h.


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