COSA
An Object-Oriented Platform for Arduino Programming
ProtoThread.hh File Reference
#include "Cosa/Job.hh"
#include "Cosa/Event.hh"
Include dependency graph for ProtoThread.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ProtoThread
 

Macros

#define PROTO_THREAD_BEGIN()   if (m_ip != 0) goto *m_ip
 
#define PROTO_THREAD_YIELD()
 
#define PROTO_THREAD_SLEEP()
 
#define PROTO_THREAD_WAKE(thread)
 
#define PROTO_THREAD_AWAIT(condition)
 
#define PROTO_THREAD_DELAY(ms)
 
#define PROTO_THREAD_END()
 

Detailed Description

Version
1.0

License

Copyright (C) 2012-2015, Mikael Patel

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

This file is part of the Arduino Che Cosa project.

Definition in file ProtoThread.hh.

Macro Definition Documentation

#define PROTO_THREAD_AWAIT (   condition)
Value:
do { \
__label__ next; \
next: \
if (!(condition)) { \
m_ip = &&next; \
return; \
} \
} while (0)

Check if the given condition is true(1). If not the thread will yield. The condition is rechecked when the thread is activated again.

Parameters
[in]conditionto evaluate.

Definition at line 240 of file ProtoThread.hh.

#define PROTO_THREAD_BEGIN ( )    if (m_ip != 0) goto *m_ip

First statement in the thread body, run(). Last statement should be PROTO_THREAD_END();

Definition at line 198 of file ProtoThread.hh.

#define PROTO_THREAD_DELAY (   ms)
Value:
do { \
set_timer(ms); \
PROTO_THREAD_AWAIT(timer_expired()); \
} while (0)
#define PROTO_THREAD_AWAIT(condition)
Definition: ProtoThread.hh:240

Delay the thread for the given ms time period. This is a short form for set_timer() and THREAD_AWAIT(timer_expired());

Parameters
[in]msmilli-seconds to delay.

Definition at line 255 of file ProtoThread.hh.

#define PROTO_THREAD_END ( )
Value:
do { \
return; \
} while (0)
void end()
Definition: ProtoThread.hh:94

Marks the running thread as TERMINATED and detach from any queue. Should be the last statement in the thread run() function.

Definition at line 265 of file ProtoThread.hh.

#define PROTO_THREAD_SLEEP ( )
Value:
do { \
m_state = SLEEPING; \
detach(); \
} while (0)
#define PROTO_THREAD_YIELD()
Definition: ProtoThread.hh:205

Yield execution and detach from the run queue. Must be activated with PROTO_THREAD_WAkE().

Definition at line 217 of file ProtoThread.hh.

#define PROTO_THREAD_WAKE (   thread)
Value:
do { \
if (thread->m_state == SLEEPING) \
Thread::schedule(thread); \
} while (0)

Schedule the given thread if SLEEPING.

Parameters
[in]threadto wake.

Definition at line 228 of file ProtoThread.hh.

#define PROTO_THREAD_YIELD ( )
Value:
do { \
__label__ next; \
m_ip = &&next; \
return; \
next: ; \
} while (0)

Yield execution to other threads ane event handlers. Remains in the run queue.

Definition at line 205 of file ProtoThread.hh.