-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_threads.cpp
More file actions
88 lines (70 loc) · 2.02 KB
/
test_threads.cpp
File metadata and controls
88 lines (70 loc) · 2.02 KB
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
#include "proto.hpp"
#include "os.hpp"
#include <iostream>
#include <cstdint>
using std::cout;
static void AssertWarn(bool MustBeTrue, const char * pMessage)
{
if (!MustBeTrue) {
cout << pMessage << '\n';
}
}
struct MyObject : public Proto::Worker<int>
{
uint32_t m_ObjectMember = 0;
struct sTestThread_Data {
int i;
bool TimedOut;
int Value;
} TestThread_Data;
Proto::Thread TestThread_Instance;
Proto::Thread ControllerThread_Instance;
void Run()
{
[&](Proto::Thread& rThread, sTestThread_Data& rData) {
ThreadBegin();
for (rData.i = 1; rData.i <= 5; rData.i++) {
cout << "TestThread: Iteration " << rData.i << '\n';
ThreadDelayUS(300);
}
ThreadWaitCond(!QueueIsEmpty());
rData.Value = Pop();
cout << "Popped value: " << rData.Value << '\n';
cout << "TestThread: DelaySeconds\n";
ThreadDelaySeconds(1);
cout << "TestThread: Yield\n";
ThreadYield();
m_ObjectMember += 1;
cout << "TestThread: WaitCond\n";
ThreadWaitCond(true);
cout << "TestThread: WaitCond_Timeout 1\n";
ThreadWaitCond_TimeoutMS(true, 100, &rData.TimedOut);
AssertWarn(!rData.TimedOut, "Should not have timed out.");
cout << "TestThread: WaitCond_Timeout 2\n";
ThreadWaitCond_TimeoutMS(false, 100, &rData.TimedOut);
AssertWarn(rData.TimedOut, "Should have timed out.");
cout << "TestThread: Exit (to ThreadFinally)\n";
ThreadExit();
cout << "TestThread: Should not get here\n";
ThreadFinally();
cout << "TestThread: Exiting\n";
ThreadEnd();
}(TestThread_Instance, TestThread_Data);
[&](Proto::Thread& rThread) {
ThreadBegin();
Push(6);
ThreadWaitCond(TestThread_Instance.Join());
cout << "COMPLETE. Exiting.\n";
OS::Exit(1);
ThreadEnd();
}(ControllerThread_Instance);
}
};
int main()
{
MyObject MyObject;
for (;;) {
Proto::Run();
OS::DelayMS(1);
}
}