-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (70 loc) · 2.37 KB
/
main.cpp
File metadata and controls
99 lines (70 loc) · 2.37 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
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include "bratley.hpp"
struct context_t
{
int m_data;
};
class task_1_t : public bratley::task_t<context_t, 4, 2, 7>
{
public:
virtual void task(context_t &context) override
{
std::cout << "Executing task 1" << std::endl;
// Modify some data
context.m_data = 1;
// Perform some computation for an amount of time less than the cost
std::this_thread::sleep_for(s_cost_duration - std::chrono::milliseconds(100));
}
};
class task_2_t : public bratley::task_t<context_t, 1, 1, 5>
{
public:
virtual void task(context_t &context) override
{
std::cout << "Executing task 2" << std::endl;
// Modify some data
context.m_data = 2;
// Perform some computation for an amount of time less than the cost
std::this_thread::sleep_for(s_cost_duration - std::chrono::milliseconds(100));
}
};
class task_3_t : public bratley::task_t<context_t, 1, 2, 6>
{
public:
virtual void task(context_t &context) override
{
std::cout << "Executing task 3" << std::endl;
// Modify some data
context.m_data = 3;
// Perform some computation for an amount of time less than the cost
std::this_thread::sleep_for(s_cost_duration - std::chrono::milliseconds(100));
}
};
//class task_4_t : public bratley::task_t<context_t, 2, 1, 3> // From the exam
class task_4_t : public bratley::task_t<context_t, 0, 2, 4> // From the book
{
public:
virtual void task(context_t &context) override
{
std::cout << "Executing task 4" << std::endl;
// Modify some data
context.m_data = 4;
// Perform some computation for an amount of time less than the cost
std::this_thread::sleep_for(s_cost_duration - std::chrono::milliseconds(100));
}
};
int main(int argc, char **argv)
{
auto schedules = bratley::schedule<task_1_t, task_2_t, task_3_t, task_4_t>();
static_assert(std::tuple_size_v<decltype(schedules)> > 0, "No valid schedules");
std::cout << "Number of valid schedules = " << std::tuple_size_v<decltype(schedules)> << std::endl;
auto schedule = std::get<0>(schedules);
context_t context;
if (bratley::execute(context, schedule) == bratley::execute_status_t::SUCCESS) {
std::cout << "SUCCESS" << std::endl;
}
else {
std::cout << "FAILURE" << std::endl;
}
return 0;
}