PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Public Member Functions | Static Public Member Functions | List of all members
PropWare::Runnable Class Referenceabstract

Helper class for creating easy parallel applications. More...

#include <PropWare/concurrent/runnable.h>

+ Inheritance diagram for PropWare::Runnable:

Public Member Functions

virtual void run ()=0
 Invoked in the new cog, this method should be the root of the business logic.
 

Static Public Member Functions

template<class T >
static int8_t invoke (T &runnable)
 Start a new cog running the given object. More...
 

Detailed Description

Helper class for creating easy parallel applications.

To create a Runnable instance which will blink an LED, try the simple example below:

public:
template<size_t N>
BlinkingThread (const uint32_t (&stack)[N], const PropWare::Pin::Mask mask)
: Runnable(stack),
m_mask(mask) {}
void run () {
const PropWare::Pin pin(this->m_mask, PropWare::Pin::OUT);
while (1) {
pin.toggle();
waitcnt(250 * MILLISECOND + CNT);
}
}
private:
const PropWare::Pin::Mask m_mask;
};
int main () {
uint32_t stack[64];
BlinkingThread blinkyThread(stack, PropWare::Pin::P16);
int8_t cog = PropWare::Runnable::invoke(blinkyThread);
pwOut << "Blink thread started in cog " << cog << "\n";
while(1);
}
Examples
DualPWM_Demo.cpp, I2CSlave_Demo.cpp, Runnable_Demo.cpp, SynchronousPrinter_Demo.cpp, UARTRX_Demo.cpp, and WatchDog_Demo.cpp.

Definition at line 75 of file runnable.h.

Member Function Documentation

◆ invoke()

template<class T >
static int8_t PropWare::Runnable::invoke ( T &  runnable)
static

Start a new cog running the given object.

Parameters
[in]runnableObject that should be invoked in a new cog
Returns
If the cog was successfully started, the new cog ID is returned. Otherwise, -1 is returned

Definition at line 85 of file runnable.h.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file:
runnable.h
printer.h
BlinkingThread
Definition: Runnable_Demo.cpp:30
PropWare::Port::Mask
Mask
Definition: port.h:43
PropWare::Runnable::invoke
static int8_t invoke(T &runnable)
Start a new cog running the given object.
Definition: runnable.h:85
PropWare::Pin
Utility class to handle general purpose I/O pins.
Definition: pin.h:36
PropWare::Port::P16
@ P16
Definition: port.h:60
main
int main(void)
Definition: GraphicsTest.c:20
PropWare.h
PropWare::Runnable
Helper class for creating easy parallel applications.
Definition: runnable.h:75
PropWare::Runnable::run
virtual void run()=0
Invoked in the new cog, this method should be the root of the business logic.
pwOut
PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
pin.h