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;
59 bool threadCreated = false;
63 JobQueue<512> jobQueue;
64
65 ThreadCtx() = default;
66 ~ThreadCtx() = default;
67
68 void reset() {
69 threadCreated = false;
70 event.reset();
71 jobQueue.clear();
72 }
73
74 ThreadCtx(const ThreadCtx& other) = delete;
75 ThreadCtx& operator=(const ThreadCtx& other) = delete;
76 ThreadCtx(ThreadCtx&& other) = delete;
77 ThreadCtx& operator=(ThreadCtx&& other) = delete;
78 };
79 } // namespace mt
80} // 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:61
ThreadPool * tp
Thread pool pointer.
Definition jobcommon.h:53
bool threadCreated
True when the worker thread has been successfully created.
Definition jobcommon.h:59
JobQueue< 512 > jobQueue
Lock-free work stealing queue for the jobs.
Definition jobcommon.h:63