Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
jobcommon.h
1#pragma once
2
3#include <inttypes.h>
4// TODO: Currently necessary due to std::function. Replace them!
5#include <functional>
6
7#include "gaia/core/utility.h"
8#include "gaia/mt/event.h"
9#include "gaia/mt/jobqueue.h"
10
11namespace gaia {
12 namespace mt {
13 enum class JobPriority : uint8_t {
15 High = 0,
17 Low = 1
18 };
19 static inline constexpr uint32_t JobPriorityCnt = 2;
20
21 enum JobCreationFlags : uint8_t {
22 Default = 0,
24 ManualDelete = 0x01,
26 CanWait = 0x02
27 };
28
29 struct JobAllocCtx {
30 JobPriority priority;
31 };
32
33 struct Job {
34 std::function<void()> func;
35 JobPriority priority = JobPriority::High;
36 JobCreationFlags flags = JobCreationFlags::Default;
37 };
38
39 struct JobArgs {
40 uint32_t idxStart;
41 uint32_t idxEnd;
42 };
43
44 struct JobParallel {
45 std::function<void(const JobArgs&)> func;
46 JobPriority priority = JobPriority::High;
47 };
48
49 class ThreadPool;
50
51 struct ThreadCtx {
55 uint32_t workerIdx;
57 JobPriority prio;
61 JobQueue<512> jobQueue;
62
63 ThreadCtx() = default;
64 ~ThreadCtx() = default;
65
66 void reset() {
67 event.reset();
68 jobQueue.clear();
69 }
70
71 ThreadCtx(const ThreadCtx& other) = delete;
72 ThreadCtx& operator=(const ThreadCtx& other) = delete;
73 ThreadCtx(ThreadCtx&& other) = delete;
74 ThreadCtx& operator=(ThreadCtx&& other) = delete;
75 };
76 } // namespace mt
77} // namespace gaia
Definition event.h:18
Definition threadpool.h:87
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9
Definition jobcommon.h:29
Definition jobcommon.h:39
Definition jobcommon.h:44
Definition jobcommon.h:33
Definition jobcommon.h:51
JobPriority prio
Job priority.
Definition jobcommon.h:57
uint32_t workerIdx
Worker index.
Definition jobcommon.h:55
Event event
Event signaled when a job is executed.
Definition jobcommon.h:59
ThreadPool * tp
Thread pool pointer.
Definition jobcommon.h:53
JobQueue< 512 > jobQueue
Lock-free work stealing queue for the jobs.
Definition jobcommon.h:61