--- nono/vm/vm.cpp 2026/04/29 17:04:32 1.1.1.3 +++ nono/vm/vm.cpp 2026/04/29 17:04:42 1.1.1.5 @@ -1,12 +1,14 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "vm.h" #include "bus.h" #include "mainapp.h" #include "mpu.h" +#include "mythread.h" #include "ram.h" #include "renderer.h" #include "scheduler.h" @@ -18,10 +20,9 @@ VM::VM() { // どこでやるのがいいかわからんけど、このコンストラクタはメインスレッドで // 作られるので、ここでメインスレッドの名前を設定。 - pthread_setname_np("Main"); + PTHREAD_SETNAME("Main"); - // Scheduler は必ず先頭。(Scheduler::Init のコメント参照) - gScheduler.reset(new Scheduler()); + // バスエラーデバイスだけここで作成。 buserr.reset(new BusErrDevice()); // まず全域をバスエラーで初期化。 @@ -34,12 +35,21 @@ VM::VM() // デストラクタ VM::~VM() { - // スケジューラを停止。 - // スケジューラ(VMスレッド)からのアクセスさえなくなれば - // 後の有象無象はグローバルデストラクタにお任せでもいいか。 - // だめだったらもっと頑張る。 - gScheduler->Terminate(); - gScheduler.reset(); + Dispose(); +} + +// 終了 +void +VM::Dispose() +{ + if ((bool)gScheduler) { + // スケジューラを停止。 + // スケジューラ(VMスレッド)からのアクセスさえなくなれば + // 後の有象無象はグローバルデストラクタにお任せでもいいか。 + // だめだったらもっと頑張る。 + gScheduler->Terminate(); + gScheduler.reset(); + } } // コンストラクタ後の初期化 @@ -95,7 +105,6 @@ VM::DevicePowerOn() ResetHard(); // スケジューラを開始 - // (MPU の ResetHard() より後で起動時に1回だけ呼び出す) gScheduler->Run(); return true;