39 #define global_logging 0
41 #define BMPTK_RTOS_STATISTICS_ENABLED 1
51 #if BMPTK_RTOS_STATISTICS_ENABLED
52 #define BMPTK_RTOS_STATISTICS( x ) x
54 #define BMPTK_RTOS_STATISTICS( x )
65 template <
class T, const
int SIZE>
class channel;
66 template <
class T>
class pool;
92 void print( std::ostream & stream );
133 void print( std::ostream &
s,
bool header )
const;
143 return ! ( *
this == rhs );
148 return ! ( *
this == rhs );
169 event(
task * t,
unsigned int mask ): t( t ), mask( mask ){}
171 friend class waitable_set;
172 friend class waitable;
173 friend class channel_base;
176 friend class callback;
225 virtual void clear();
237 BMPTK_RTOS_STATISTICS(
const char *waitable_name; )
239 friend class waitable_set;
288 flag(
task * t,
const char *name =
"" );
297 void print( std::ostream &
s,
bool header =
true )
const;
302 BMPTK_RTOS_STATISTICS(
flag *next_flag; )
303 BMPTK_RTOS_STATISTICS(
unsigned int n_sets; )
304 BMPTK_RTOS_STATISTICS(
unsigned int n_gets; )
307 friend class waitable_set;
308 friend void add(
flag * f );
309 friend void print( std::ostream & stream );
325 event wait(
unsigned int mask );
329 unsigned int current_waitables;
330 unsigned int requested_waitables;
333 waitable_set(
task * client ):
335 current_waitables( 0 ),
336 requested_waitables( 0 ),
339 unsigned int waitable_allocate();
340 void set(
const waitable &w );
341 void clear(
const waitable &w );
344 event wait(
const waitable & w ){
345 return wait( w.mask );
347 event wait(
const event &
set ){
348 return wait(
set.mask );
420 bool task_is_blocked;
423 unsigned int task_priority;
428 friend void task_trampoline();
429 friend void sleep_until(
time t );
434 BMPTK_RTOS_STATISTICS(
const char *task_name; )
460 virtual void main() = 0;
478 const char * tname =
"",
495 return task_priority;
500 #if BMPTK_RTOS_STATISTICS_ENABLED
509 return ! task_is_blocked;
513 return task_is_blocked;
517 void print( std::ostream & stream,
bool header =
true )
const;
533 event wait(){
return waitables.wait(); }
539 return waitables.wait( w );
546 return waitables.wait(
set );
563 ignore_this_activation =
true;
569 void statistics_clear(){
570 runtime_max = 0 *
ms;
575 waitable_set waitables;
588 bool ignore_this_activation;
594 task * next_mutex_waiter;
599 friend class periodic_task;
600 friend class waitable_set;
602 friend class waitable;
604 friend void print( std::ostream & stream );
605 friend void do_statistics_clear();
606 friend void add(
task * new_task );
622 class callback :
public waitable {
625 callback( task *t,
const char *name );
628 virtual ~callback() {
633 virtual void time_up(
void ) = 0;
636 void print( std::ostream &
s,
bool header =
true )
const;
641 void await( time t ){
647 void start( time t ){
653 void restart( time t ){
655 while( deadline <= now ){
662 virtual void cancel(){
673 callback * next_callback;
677 friend void add( callback * t );
678 friend void handle_callbacks( time t );
719 timer(
task * t,
const char *name =
"" );
743 void print( std::ostream &
s,
bool header =
true )
const;
748 BMPTK_RTOS_STATISTICS(
timer *next_timer; )
749 BMPTK_RTOS_STATISTICS(
unsigned int n_sets; )
750 BMPTK_RTOS_STATISTICS(
unsigned int n_cancels; )
752 friend void add(
timer * t );
753 friend void print( std::ostream & stream );
789 const char *name =
""
803 void print( std::ostream &
s,
bool header =
true )
const;
808 BMPTK_RTOS_STATISTICS(
clock *next_clock; )
809 BMPTK_RTOS_STATISTICS(
unsigned int ticks; )
811 friend void add(
clock * c );
813 friend void print( std::ostream & stream );
830 pool_base(
const char * name );
834 void print( std::ostream &
s,
bool header =
true )
const;
836 #if BMPTK_RTOS_STATISTICS_ENABLED
839 pool_base * next_pool;
840 const char * pool_name;
895 template <
class T>
class pool :
public pool_base {
905 pool(
const char *name =
"" ): pool_base( name ){}
917 BMPTK_RTOS_STATISTICS( reads++; )
925 BMPTK_RTOS_STATISTICS( writes++; )
977 mutex(
const char *name =
"" );
985 void print( std::ostream & stream,
bool header =
true )
const;
1014 #if BMPTK_RTOS_STATISTICS_ENABLED
1015 const char * mutex_name;
1020 friend void add(
mutex * m );
1021 friend void print( std::ostream & stream );
1035 class mailbox_base {
1037 mailbox_base(
const char *name );
1043 void print( std::ostream &
s,
bool header =
true )
const;
1046 #if BMPTK_RTOS_STATISTICS_ENABLED
1047 const char * mailbox_name;
1048 unsigned int writes;
1049 mailbox_base *next_mailbox;
1100 mailbox(
const char *name =
"" ): mailbox_base( name ){}
1112 BMPTK_RTOS_STATISTICS( writes++; )
1114 if ( client != 0 ) {
1134 if ( client == 0 ) {
1142 task *temp = client;
1163 class channel_base :
public waitable{
1165 virtual ~channel_base() {
1169 void print( std::ostream &
s,
bool header =
true )
const;
1174 channel_base( task * t,
const char *name );
1176 #if BMPTK_RTOS_STATISTICS_ENABLED
1177 const char *channel_name;
1178 channel_base *next_channel;
1252 template <
class T, const
int SIZE>
class channel :
public channel_base {
1263 if( qSize < SIZE ) {
1264 BMPTK_RTOS_STATISTICS( writes++; )
1266 if( ++head == SIZE ) {
1272 BMPTK_RTOS_STATISTICS( ignores++; )
1285 T buf = queue[ tail ];
1286 if( ++tail == SIZE ) {
1320 std::ostream &
operator<< ( std::ostream &
s,
const bmptk::rtos::callback & c );
1329 std::ostream &
operator<< ( std::ostream &
s,
const bmptk::rtos::channel_base & c );
1335 std::ostream &
operator<< ( std::ostream &
s,
const bmptk::rtos::mailbox_base & m );
1338 std::ostream &
operator<< ( std::ostream &
s,
const bmptk::rtos::pool_base & p );