-
Notifications
You must be signed in to change notification settings - Fork 0
/
oosmos.hpp
124 lines (99 loc) · 5.48 KB
/
oosmos.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef OOSMOS_HPP
#define OOSMOS_HPP
#include <cstdint>
#include <list>
using namespace std;
namespace OOSMOS {
struct cTimeout {
cTimeout();
void TimeoutInSeconds(uint32_t TimeoutSeconds);
void TimeoutInMS(uint32_t TimeoutMS);
void TimeoutInUS(uint32_t TimeoutUS);
bool HasExpired() const;
uint32_t m_StartUS;
uint32_t m_TimeoutUS;
};
struct cStack {
cStack();
int32_t m_ThreadContext;
bool m_FirstEntry;
cTimeout m_ThreadTimeout;
bool OOSMOS_ThreadDelayUS(uint32_t US);
bool OOSMOS_ThreadDelayMS(uint32_t MS);
bool OOSMOS_ThreadDelaySeconds(uint32_t Seconds);
bool OOSMOS_ThreadWaitCond_TimeoutMS(bool Condition, uint32_t TimeoutMS, bool * pTimeoutStatus);
bool OOSMOS_ThreadYield();
#define OOSMOS_THREAD_CONTEXT_BEGIN (-1)
#define OOSMOS_THREAD_CONTEXT_FINALLY (-2)
#define OOSMOS_THREAD_CONTEXT_END (-3)
// The underlying structure of OOSMOS C++ State Threads and Object Threads is based
// on protothreads by Adam Dunkels.
#define ThreadBegin() \
switch (rStack.m_ThreadContext) { \
case OOSMOS_THREAD_CONTEXT_BEGIN:
#define ThreadDelayUS(US) \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
do { case __LINE__: rStack.m_ThreadContext = __LINE__; \
if (!rStack.OOSMOS_ThreadDelayUS(US)) \
return; \
} while (0)
#define ThreadDelayMS(MS) \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
do { case __LINE__: rStack.m_ThreadContext = __LINE__; \
if (!rStack.OOSMOS_ThreadDelayMS(MS)) \
return; \
} while (0)
#define ThreadDelaySeconds(Seconds) \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
do { case __LINE__: rStack.m_ThreadContext = __LINE__; \
if (!rStack.OOSMOS_ThreadDelaySeconds(Seconds)) \
return; \
} while (0)
#define ThreadYield() \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
do { case __LINE__: rStack.m_ThreadContext = __LINE__; \
if (!rStack.OOSMOS_ThreadYield()) \
return; \
} while (0)
#define ThreadWaitCond(Cond) \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
do { case __LINE__: rStack.m_ThreadContext = __LINE__; \
if (!(Cond)) \
return; \
} while (0)
#define ThreadWaitCond_TimeoutMS(Cond, TimeoutMS, pTimeoutStatus) \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
do { case __LINE__: rStack.m_ThreadContext = __LINE__; \
if (!rStack.OOSMOS_ThreadWaitCond_TimeoutMS(Cond, TimeoutMS, pTimeoutStatus)) \
return; \
} while(0)
#define ThreadExit() \
do { rStack.m_ThreadContext = OOSMOS_THREAD_CONTEXT_FINALLY; \
return; \
} while (0)
#define ThreadFinally() \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
do { case OOSMOS_THREAD_CONTEXT_FINALLY: rStack.m_ThreadContext = OOSMOS_THREAD_CONTEXT_END; \
} while (0)
#define ThreadEnd() \
/*lint -e646 suppress "case/default within for loop; may have been misplaced" */ \
/*lint -fallthrough*/ \
default: \
rStack.m_ThreadContext = OOSMOS_THREAD_CONTEXT_END; \
} return
};
struct cObject {
cObject();
void AssertWarn(bool, const char *) const;
virtual void Run(void) = 0;
};
extern void Run(void);
extern list<struct cObject *> m_ObjectList;
}
#endif