PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
PropWare
concurrent
runnable.h
Go to the documentation of this file.
1
26
#pragma once
27
28
#include <type_traits>
29
#include <propeller.h>
30
#include <cstdint>
31
#include <stdlib.h>
32
33
namespace
PropWare
{
34
75
class
Runnable
{
76
public
:
84
template
<
class
T>
85
static
int8_t
invoke
(T &runnable) {
86
static_assert(std::is_base_of<Runnable, T>::value,
87
"Only PropWare::Runnable and its children can be invoked"
);
88
#pragma GCC diagnostic push
89
#pragma GCC diagnostic ignored "-Wpmf-conversions"
90
return
(int8_t)
cogstart
((
void
(*)(
void
*)) &T::run, (
void
*) &runnable,
91
(
void
*) (runnable.m_stackPointer), runnable.m_stackSizeInBytes);
92
#pragma GCC diagnostic pop
93
}
94
95
public
:
99
virtual
void
run
() = 0;
100
101
protected
:
107
template
<
size_t
N>
108
Runnable
(
const
uint32_t (&stack)[N])
109
: m_stackPointer(stack),
110
m_stackSizeInBytes(N * sizeof(uint32_t)) {
111
}
112
129
Runnable(
const
uint32_t *stack,
const
size_t
stackLength)
130
: m_stackPointer(stack),
131
m_stackSizeInBytes(stackLength * sizeof(uint32_t)) {
132
}
133
134
protected
:
135
const
uint32_t *m_stackPointer;
136
size_t
m_stackSizeInBytes;
137
};
138
139
}
PropWare::Runnable::invoke
static int8_t invoke(T &runnable)
Start a new cog running the given object.
Definition:
runnable.h:85
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.
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition:
runnable.h:33
cogstart
int cogstart(void(*func)(void *), void *par, void *stack, size_t stacksize)
Start a new propeller LMM function/thread in another COG.
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17