--- nono/vm/scheduler.h 2026/04/29 17:05:11 1.1.1.11 +++ nono/vm/scheduler.h 2026/04/29 17:05:25 1.1.1.13 @@ -10,15 +10,17 @@ #pragma once +#include "thread.h" #include "event.h" #include "message.h" #include "monitor.h" #include "spscqueue.h" -#include "thread.h" #include #include #include +class Syncer; + // スケジューラ class Scheduler : public ThreadDevice { @@ -26,8 +28,8 @@ class Scheduler : public ThreadDevice private: // リクエストフラグ - static const uint32 REQUEST_EXIT = 0x80000000; // 終了要求 - static const uint32 REQUEST_MESSAGE = 0x00000001; // メッセージ要求 + static const uint32 REQUEST_EXIT = 0x00000001; // 終了要求 + static const uint32 REQUEST_MESSAGE = 1U << MessageID::MAX_REQUEST; // メッセージハンドラを覚えておくための構造体 struct MessageHandler @@ -38,7 +40,7 @@ class Scheduler : public ThreadDevice public: Scheduler(); - virtual ~Scheduler() override; + ~Scheduler() override; bool Init() override; @@ -51,7 +53,7 @@ class Scheduler : public ThreadDevice uint64 GetVirtTime() const { return vtime; } // イベントを登録する - void RegistEvent(Event& event); + void RegistEvent(Event& ev); // イベントを開始する void StartEvent(Event& ev); @@ -60,10 +62,10 @@ class Scheduler : public ThreadDevice // 実時間間隔を指定してイベントを開始する。 // rt_now はイベント発行者の実時間での現在時刻で、 // rt_period は次回のイベントまでの実時間間隔。 - void StartRealtimeEvent(Event& event, uint64 rt_now, uint64 rt_period); + void StartRealtimeEvent(Event& ev, uint64 rt_now, uint64 rt_period); // イベントを停止する - void StopEvent(Event& event); + void StopEvent(Event& ev); // メッセージハンドラを登録する void ConnectMessage(MessageID, Device *, MessageCallback_t); @@ -84,6 +86,7 @@ class Scheduler : public ThreadDevice // メッセージディスパッチ void DispatchMessage(); + void InvokeMessage(MessageID, uint32); DECLARE_MONITOR_CALLBACK(MonitorUpdate); @@ -97,7 +100,7 @@ class Scheduler : public ThreadDevice uint64 vtime {}; // 外部スレッドからのリクエスト - int request {}; + uint32 request {}; std::mutex mtx {}; std::condition_variable cv {}; @@ -110,10 +113,14 @@ class Scheduler : public ThreadDevice // メッセージキュー SPSCQueue msgq {}; + Syncer *syncer {}; + Monitor monitor { this }; }; extern const std::string TimeToStr(uint64 t); extern const std::string SecToStr(uint64 t); -extern Scheduler *gScheduler; +static inline Scheduler *GetScheduler() { + return Object::GetObject(OBJ_SCHEDULER); +}