Skip to content
LeviMC
English
AutoLightDark
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 // prevent constructor by default
65 BackgroundWorker& operator=(BackgroundWorker const&);
66 BackgroundWorker(BackgroundWorker const&);
67 BackgroundWorker();
68
69public:
70 // virtual functions
71 // NOLINTBEGIN
72 virtual ~BackgroundWorker() /*override*/ = default;
73
74 virtual bool isAsync() const /*override*/;
75
76 virtual bool canTaskRunAgain() const /*override*/;
77 // NOLINTEND
78
79public:
80 // member functions
81 // NOLINTBEGIN
83 ::std::string_view name,
84 ::Core::Profile::ThreadFrameType frameType,
85 bool async,
87 ::std::optional<uint64> const coreAffinity,
88 ::std::optional<int> const idealCore,
89 ::WorkerPool& workerPool
90 );
91
92 MCNAPI bool _processNextTask(::RunTaskOptions const& options);
93
94 MCNAPI void queue(::std::shared_ptr<::BackgroundTaskBase> task);
95
96 MCNAPI void requestStop(bool wait);
97
98 MCNAPI void start();
99 // NOLINTEND
100
101public:
102 // constructor thunks
103 // NOLINTBEGIN
104 MCNAPI void* $ctor(
105 ::std::string_view name,
106 ::Core::Profile::ThreadFrameType frameType,
107 bool async,
109 ::std::optional<uint64> const coreAffinity,
110 ::std::optional<int> const idealCore,
111 ::WorkerPool& workerPool
112 );
113 // NOLINTEND
114
115public:
116 // virtual function thunks
117 // NOLINTBEGIN
118 MCNAPI bool $isAsync() const;
119
120 MCNAPI bool $canTaskRunAgain() const;
121
122
123 // NOLINTEND
124};
Definition BackgroundTaskBase.h:71
Definition BackgroundTaskBase.h:18
MCAPI bool $isAsync() const
MCAPI BackgroundWorker(::std::string_view name, ::Core::Profile::ThreadFrameType frameType, bool async, ::Bedrock::Threading::OSThreadPriority const &priority, ::std::optional< uint64 > const coreAffinity, ::std::optional< int > const idealCore, ::WorkerPool &workerPool)
MCAPI void requestStop(bool wait)
MCAPI bool $canTaskRunAgain() const
MCAPI void start()
MCAPI void queue(::std::shared_ptr<::BackgroundTaskBase > task)
MCAPI void * $ctor(::std::string_view name, ::Core::Profile::ThreadFrameType frameType, bool async, ::Bedrock::Threading::OSThreadPriority const &priority, ::std::optional< uint64 > const coreAffinity, ::std::optional< int > const idealCore, ::WorkerPool &workerPool)
MCAPI bool _processNextTask(::RunTaskOptions const &options)
Definition OSThreadPriority.h:7
Definition ITaskExecutionContext.h:5
Definition MovePriorityQueue.h:6
Definition SPSCQueue.h:6
Definition WorkerPool.h:22
Definition RunTaskOptions.h:5