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::pool< T > Class Template Reference

rtos private implementation class More...

#include <rtos.h>

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

Public Member Functions

 pool (const char *name="")
 construct a pool, specify its name (for debgging only)
 
void write (T item)
 atomic write operation on a pool
 
read (void)
 atomic read operation on a pool
 

Detailed Description

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

rtos private implementation class

place to store and retrieve data, no built-in synchronisation A (communication) pool is a template class that stores a single value. It supports the read and write operations, which are guaranteed to be atomic. (On a non-preemptive rtos every assignment is atomic, but the pool template is still usefull to make it explicit that data is transferred between tasks.)

The example below demonstrates the use of a pool to maintain a seconds-since-startup counter. Note that the call RTOS::runtime() returns the time elapsed since startup, so there is no need to maintain a seconds-since-startup this way yourself.

<< code >> make it an example

void show_time(){
unsigned int n = seconds.read();
std::cout << ( seconds / 60 ) % 60 << ":" << seconds % 60;
}
class seconds_counter_class : public periodic_task {
seconds_counter(){
periodic_task::periodic_task( "sec-counter", 10, 1000 MS );
seconds.write( 0 );
}
void main(){
for(;;){
(void)wait(); // only one thing to wait for
seconds.write( seconds.read() + 1 );
}
}
}
seconds_counter_class seconds_counter;

Definition at line 895 of file rtos.h.

Constructor & Destructor Documentation

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

construct a pool, specify its name (for debgging only)

Use it to make (global) variables use for communication between tasks explicit.

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

Definition at line 905 of file rtos.h.

Member Function Documentation

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

atomic read operation on a pool

A read operation returns the most recently written data.In the context of co-operative multitasking a read of write operation on anything is always atomic, unless the implementation of that operating somehow invokes the rtos. But for clearness it is a good idea to implement such task-global data as pools.

Definition at line 924 of file rtos.h.

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

atomic write operation on a pool

A read operation returns the most recently written data.

In the context of co-operative multitasking a read of write operation on anything is always atomic, unless the implementation of that operating somehow invokes the rtos. But for clearness it is a good idea to implement such task-global data as pools.

Definition at line 916 of file rtos.h.


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