-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_threads.cpp
67 lines (53 loc) · 1.46 KB
/
test_threads.cpp
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
#include "oosmos.hpp"
#include "os.hpp"
#include <iostream>
#include <cstdint>
using namespace std;
struct cMyObject : public OOSMOS::cObject
{
uint32_t m_ObjectMember = 0;
struct cTestThreadStack : public OOSMOS::cStack
{
int i;
bool TimedOut;
} TestThread_Stack;
void TestThread(cTestThreadStack& rStack)
{
ThreadBegin();
for (rStack.i = 1; rStack.i <= 5; rStack.i++) {
cout << "TestThread: Iteration " << rStack.i << endl;
ThreadDelayUS(300);
}
cout << "TestThread: DelaySeconds" << endl;
ThreadDelaySeconds(1);
cout << "TestThread: Yield" << endl;
ThreadYield();
m_ObjectMember += 1;
cout << "TestThread: WaitCond" << endl;
ThreadWaitCond(true);
cout << "TestThread: WaitCond_Timeout 1" << endl;
ThreadWaitCond_TimeoutMS(true, 100, &rStack.TimedOut);
AssertWarn(!rStack.TimedOut, "Should not have timed out.");
cout << "TestThread: WaitCond_Timeout 2" << endl;
ThreadWaitCond_TimeoutMS(false, 100, &rStack.TimedOut);
AssertWarn(rStack.TimedOut, "Should have timed out.");
cout << "TestThread: Exit (to ThreadFinally)" << endl;
ThreadExit();
cout << "TestThread: Should not get here" << endl;
ThreadFinally();
cout << "TestThread: Exiting" << endl;
ThreadEnd();
}
void Run()
{
TestThread(TestThread_Stack);
}
};
int main()
{
cMyObject MyObject;
for (;;) {
OOSMOS::Run();
OS::DelayMS(1);
}
}