--- nono/vm/scheduler.h 2026/04/29 17:04:28 1.1.1.1 +++ nono/vm/scheduler.h 2026/04/29 17:04:39 1.1.1.4 @@ -1,22 +1,24 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once +#include "device.h" +#include "event.h" +#include "mpu.h" #include #include +#include #include #include -#include "device.h" -#include "event.h" -#include "mpu.h" // スケジューラ class Scheduler : public Device { - typedef Device inherited; + using inherited = Device; // リクエストフラグ static const uint REQ_SYNC = 0x0001; // スケジューラを同期モードに @@ -34,21 +36,29 @@ class Scheduler : public Device // なら通常走行するというロジックを比較1回で済ませるため。 static const uint32 SCHED_STOP = 0x0001; // スケジューラが STOP 状態 static const uint32 SCHED_SYNC = 0x0002; // 同期(%1)/高速(%0)モード - // 演算を1回で済ませるために、同じ値にすること + + // 演算を1回で済ませるために、この2値は同じ値にすること。 + // ただしこれをチェックするために全員が m68030.h/m88100.h を include すると + // m88k を修正するたびに m68k も含めて全部ビルドが走るのはかなりつらいので + // 定義されてる時だけチェックすることにする。 + // もともと将来のポカよけなのでビルド中1回でも通過すれば十分。 +#if defined(CPU_REQ_STOP) static_assert(SCHED_STOP == CPU_REQ_STOP, "must be the same"); +#endif public: Scheduler(); - virtual ~Scheduler(); + ~Scheduler() override; - virtual bool Init(); + bool Init() override; - virtual bool MonitorUpdate(); + nnSize GetMonitorSize() override; + void MonitorUpdate(TextScreen&) override; // スレッド開始 void ThreadRun(); - // スレッド終了指示 + // スレッド終了 void Terminate(); // スケジューラを開始 (電源オン時に vm から呼ばれる) @@ -82,10 +92,10 @@ class Scheduler : public Device // true なら高速モード、false なら同期モード。 void SetFullSpeed(bool enable); - // イベントを登録する - void AddEvent(Event *newev); - // イベントを削除する - void DelEvent(Event *event); + // イベントを開始する + void StartEvent(Event *newev); + // イベントを停止する + void StopEvent(Event *event); std::list eventlist {}; // 有効なイベントリスト std::mutex evcs {}; // イベントリストのロック @@ -99,6 +109,9 @@ class Scheduler : public Device std::mutex cvmtx {}; private: + pthread_t thread {}; + bool thread_created = false; // スレッドが作成されたら true + // スケジューラの動作モード。SCHED_* uint32 mode = 0; @@ -112,7 +125,7 @@ class Scheduler : public Device uint64 rtc_last_clock = 0; }; -extern Scheduler *gScheduler; +extern std::unique_ptr gScheduler; // 現在時刻 [nsec] を取得する static inline uint64 GetRealTime()