--- nono/vm/scheduler.h 2026/04/29 17:05:11 1.1.1.11 +++ nono/vm/scheduler.h 2026/04/29 17:06:01 1.1.1.17 @@ -10,15 +10,16 @@ #pragma once -#include "event.h" +#include "thread.h" #include "message.h" -#include "monitor.h" #include "spscqueue.h" -#include "thread.h" #include #include #include +class EventManager; +class Syncer; + // スケジューラ class Scheduler : public ThreadDevice { @@ -26,8 +27,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,9 +39,10 @@ class Scheduler : public ThreadDevice public: Scheduler(); - virtual ~Scheduler() override; + ~Scheduler() override; bool Init() override; + bool Init2(); void StartTime(); @@ -50,20 +52,17 @@ class Scheduler : public ThreadDevice // 現在のマスター仮想時間を返す uint64 GetVirtTime() const { return vtime; } - // イベントを登録する - void RegistEvent(Event& event); - // イベントを開始する - void StartEvent(Event& ev); - void RestartEvent(Event& ev); + void StartEvent(Event *ev); + void RestartEvent(Event *ev); // 実時間間隔を指定してイベントを開始する。 // 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); @@ -78,14 +77,15 @@ class Scheduler : public ThreadDevice // スレッド void ThreadRun() override; - void EnqueueSlow(Event& ev); - void PushSlow(Event& ev); - void StopSlowEvent(Event& ev); + void EnqueueSlow(Event *); + void PushSlow(Event *); + void StopSlowEvent(Event *); // メッセージディスパッチ void DispatchMessage(); + void InvokeMessage(MessageID, uint32); - DECLARE_MONITOR_CALLBACK(MonitorUpdate); + DECLARE_MONITOR_SCREEN(MonitorScreen); // 有効なイベントキュー uint64 slow_top_vtime {}; @@ -97,23 +97,22 @@ class Scheduler : public ThreadDevice uint64 vtime {}; // 外部スレッドからのリクエスト - int request {}; + uint32 request {}; std::mutex mtx {}; std::condition_variable cv {}; - // 全イベントのリスト (所有はしていない) - std::vector all_events {}; - // メッセージハンドラリスト std::array message_handlers {}; // メッセージキュー - SPSCQueue msgq {}; + SPSCQueue msgq {}; - Monitor monitor { this }; -}; + EventManager *evman {}; + Syncer *syncer {}; -extern const std::string TimeToStr(uint64 t); -extern const std::string SecToStr(uint64 t); + Monitor *monitor {}; +}; -extern Scheduler *gScheduler; +inline Scheduler *GetScheduler() { + return Object::GetObject(OBJ_SCHEDULER); +}