LeviLamina
Loading...
Searching...
No Matches
BackgroundWorker.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/container/MovePriorityQueue.h"
7#include "mc/deps/core/threading/BackgroundTaskBase.h"
8#include "mc/deps/core/threading/BackgroundTaskQueue.h"
9#include "mc/deps/core/threading/ITaskExecutionContext.h"
10#include "mc/deps/core/threading/ResetEventObj.h"
11#include "mc/deps/core/threading/SPSCQueue.h"
12#include "mc/deps/profiler/ThreadFrameType.h"
13#include "mc/platform/threading/OSThreadPriority.h"
14
15// auto generated forward declare list
16// clang-format off
18class WorkerPool;
19struct RunTaskOptions;
20// clang-format on
21
22class BackgroundWorker : public ::ITaskExecutionContext {
23public:
24 // BackgroundWorker inner types define
25 enum class RunOneResult : int {
26 NoTasks = 0,
27 TaskExecuted = 1,
28 Retry = 2,
29 };
30
31 enum class State : int {
32 Initializing = 0,
33 Off = 1,
34 Running = 2,
35 };
36
37 using SortingJobQueue =
39
41
42public:
43 // member variables
44 // NOLINTBEGIN
45 ::ll::TypedStorage<1, 1, bool const> mAsync;
46 ::ll::TypedStorage<4, 4, ::Bedrock::Threading::OSThreadPriority> mPriority;
47 ::ll::TypedStorage<8, 16, ::std::optional<uint64>> mCoreAffinity;
48 ::ll::TypedStorage<4, 8, ::std::optional<int>> mIdealCore;
49 ::ll::TypedStorage<8, 32, ::std::string> mName;
50 ::ll::TypedStorage<1, 1, ::Core::Profile::ThreadFrameType> mFrameType;
51 ::ll::TypedStorage<8, 16, ::std::thread> mThread;
52 ::ll::TypedStorage<4, 4, ::std::thread::id> mWorkerThreadID;
53 ::ll::TypedStorage<4, 4, ::std::atomic<::BackgroundWorker::State>> mState;
54 ::ll::TypedStorage<8, 160, ::ResetEventObj> mResetEvent;
55 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mIdle;
56 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mIdleSinceTime;
57 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::BackgroundTaskBase>> mCurrentTask;
58 ::ll::TypedStorage<8, 8, ::WorkerPool&> mWorkerPool;
59 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mMaxSpinlockDuration;
60 ::ll::TypedStorage<8, 360, ::BackgroundTaskQueue> mTaskQueue;
61 // NOLINTEND
62
63public:
64 static ::BackgroundWorker* getLocal() { return gLocalWorkerMappingSingleton(); }
65
66public:
67 // prevent constructor by default
68 BackgroundWorker& operator=(BackgroundWorker const&);
69 BackgroundWorker(BackgroundWorker const&);
70 BackgroundWorker();
71
72public:
73 // virtual functions
74 // NOLINTBEGIN
75 virtual ~BackgroundWorker() /*override*/ = default;
76
77 virtual bool isAsync() const /*override*/;
78
79 virtual bool canTaskRunAgain() const /*override*/;
80 // NOLINTEND
81
82public:
83 // member functions
84 // NOLINTBEGIN
85 MCAPI BackgroundWorker(
86 ::std::string_view name,
87 ::Core::Profile::ThreadFrameType frameType,
88 bool async,
90 ::std::optional<uint64> const coreAffinity,
91 ::std::optional<int> const idealCore,
92 ::WorkerPool& workerPool
93 );
94
95 MCAPI bool _processNextTask(::RunTaskOptions const& options);
96
97 MCAPI void queue(::std::shared_ptr<::BackgroundTaskBase> task);
98
99 MCAPI void requestStop(bool wait);
100
101 MCAPI void start();
102 // NOLINTEND
103
104public:
105 // static variables
106 // NOLINTBEGIN
107 MCAPI static ::BackgroundWorker*& gLocalWorkerMappingSingleton();
108 // NOLINTEND
109
110public:
111 // constructor thunks
112 // NOLINTBEGIN
113 MCAPI void* $ctor(
114 ::std::string_view name,
115 ::Core::Profile::ThreadFrameType frameType,
116 bool async,
118 ::std::optional<uint64> const coreAffinity,
119 ::std::optional<int> const idealCore,
120 ::WorkerPool& workerPool
121 );
122 // NOLINTEND
123
124public:
125 // virtual function thunks
126 // NOLINTBEGIN
127 MCFOLD bool $isAsync() const;
128
129 MCAPI bool $canTaskRunAgain() const;
130
131
132 // NOLINTEND
133};
Definition BackgroundTaskBase.h:38
Definition BackgroundTaskBase.h:18
Definition OSThreadPriority.h:7
Definition ITaskExecutionContext.h:5
Definition MovePriorityQueue.h:6
Definition SPSCQueue.h:6
Definition WorkerPool.h:16
Definition RunTaskOptions.h:5