Repository navigation
Expand file tree
/
Copy pathWorkQueue.h
More file actions
112 lines (91 loc) · 2.21 KB
/
Copy pathWorkQueue.h
File metadata and controls
112 lines (91 loc) · 2.21 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
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include <cstdint>
#include <limits>
#include <memory>
#include <utility>
namespace ra::hal
{
class WorkQueue
{
public:
class WorkHandle;
using WorkFn = void(WorkHandle&);
// Task priority
enum class Priority : uint8_t
{
RealTime = 0,
High,
Normal,
Low
};
// Execution info
struct Execution
{
Priority PriorityValue = Priority::Normal;
WorkFn* Fn = nullptr;
void* Ctx = nullptr;
// no supported yet
WorkHandle* OldHandle = nullptr;
};
// Scheduler info
struct Scheduling
{
static constexpr uint32_t IterationInfinite = std::numeric_limits<uint32_t>::max();
uint32_t DelayMs = 0;
uint32_t Iterations = 1;
};
// Full options struct
struct SubmitOptions
{
Execution Exec;
Scheduling Sched;
};
enum class Status
{
Success,
Fail,
InvalidParam,
};
public:
std::pair<Status, WorkHandle> Submit(const SubmitOptions& Options);
Status Cancel(const WorkHandle& Handle);
Status Init();
Status Deinit();
#if !(WORK_QUEUE_PREEMPTIVE)
Status Run();
#endif
public:
WorkQueue();
~WorkQueue();
// Non-copyable, movable
WorkQueue(const WorkQueue&) = delete;
WorkQueue& operator=(const WorkQueue&) = delete;
WorkQueue(WorkQueue&&) = default;
WorkQueue& operator=(WorkQueue&&) = default;
private:
class Impl;
std::unique_ptr<Impl> m_Impl;
};
class WorkQueue::WorkHandle
{
public:
void* GetContext() const;
bool IsAlive() const;
void Cancel() const;
public:
WorkHandle() = default;
WorkHandle(const WorkHandle&) = default;
WorkHandle& operator=(const WorkHandle&) = default;
WorkHandle(WorkHandle&&) = default;
WorkHandle& operator=(WorkHandle&&) = default;
~WorkHandle();
private:
// only queue implementation can manipulate
class Impl;
std::weak_ptr<Impl> m_Impl;
friend class WorkQueue;
private:
// Only WorkQueue can create this obj
explicit WorkHandle(const std::shared_ptr<class Impl>&);
};
} // namespace ra::hal