| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <array> |
| 4 | #include "container/seadBuffer.h" |
| 5 | #include "framework/seadInfLoopChecker.h" |
| 6 | #include "heap/seadDisposer.h" |
| 7 | #include "hostio/seadHostIONode.h" |
| 8 | #include "mc/seadCoreInfo.h" |
| 9 | #include "mc/seadJobQueue.h" |
| 10 | #include "mc/seadWorker.h" |
| 11 | #include "time/seadTickSpan.h" |
| 12 | #include "time/seadTickTime.h" |
| 13 | |
| 14 | namespace sead |
| 15 | { |
| 16 | class WorkerMgr : public hostio::Node |
| 17 | { |
| 18 | public: |
| 19 | struct InitializeArg |
| 20 | { |
| 21 | InitializeArg(); |
| 22 | |
| 23 | std::array<s32, 3> thread_priorities; |
| 24 | std::array<u32, 3> thread_stack_sizes; |
| 25 | u32 worker_num_jobs; |
| 26 | const char* name; |
| 27 | }; |
| 28 | |
| 29 | WorkerMgr(); |
| 30 | virtual ~WorkerMgr() = default; |
| 31 | WorkerMgr(const WorkerMgr&) = delete; |
| 32 | auto operator=(const WorkerMgr&) = delete; |
| 33 | |
| 34 | virtual void initialize(const InitializeArg& arg); |
| 35 | void finalize(); |
| 36 | |
| 37 | void pushJobQueue(JobQueue* queue, CoreIdMask core_id_mask, SyncType sync_type, |
| 38 | JobQueuePushType push_type); |
| 39 | void pushJobQueue(const char* context_name, JobQueue* queue, CoreIdMask core_id_mask, |
| 40 | SyncType sync_type, JobQueuePushType push_type); |
| 41 | void run(); |
| 42 | void sync(); |
| 43 | bool isAllWorkerSleep() const; |
| 44 | |
| 45 | protected: |
| 46 | void onInfLoop_(const InfLoopChecker::InfLoopParam& param); |
| 47 | |
| 48 | InfLoopChecker::InfLoopEvent::Slot mInfLoopEventSlot; |
| 49 | Buffer<Worker*> mWorkers; |
| 50 | Buffer<JobQueue*> mJobQueues; |
| 51 | u32 mNumJobQueues; |
| 52 | bool mProcessJobQueues = false; |
| 53 | u32 mNumWakeups = 0; |
| 54 | TickTime mLastWakeup; |
| 55 | TickSpan mWaitDuration = TickSpan::makeFromMilliSeconds(msec: 1); |
| 56 | }; |
| 57 | } // namespace sead |
| 58 |