--- nono/host/logger.cpp 2026/04/29 17:05:51 1.1.1.1 +++ nono/host/logger.cpp 2026/04/29 17:05:56 1.1.1.2 @@ -8,6 +8,9 @@ // ログ // +// Logger はモニタを持つため Object から派生しているが、(Object のもう一つの +// 機能である) ログ出力は出来ない。これは自明。 + #include "logger.h" #include "monitor.h" #include "mythread.h" @@ -18,6 +21,8 @@ Logger::Logger() : inherited(OBJ_LOGGER) { + ClearAlias(); + monitor = gMonitorManager->Regist(ID_MONITOR_LOG, this); monitor->func = ToMonitorCallback(&Logger::MonitorUpdate); monitor->SetSize(80, 40); // 初期サイズは適当 @@ -40,21 +45,14 @@ Logger::SetConverter(std::string (*conv) bool Logger::StartThread() { - auto func = [this]() { - PTHREAD_SETNAME("Logger"); - std::lock_guard lock_sub(this->thread_starter); - this->ThreadRun(); - }; - if (ResizeCol(monitor->GetCol()) == false) { return false; } - // スレッド起動 + // スレッド起動。 std::lock_guard lock(thread_starter); - try { - thread.reset(new std::thread(func)); + thread.reset(new std::thread(&Logger::OnStart, this)); } catch (...) { } if ((bool)thread == false) { warnx("Failed to initialize thread at %s", __method__); @@ -63,11 +61,30 @@ Logger::StartThread() return true; } +// 開始されたスレッドでのエントリポイント。 +void +Logger::OnStart() +{ + // このスレッドにスレッド名を設定。 + static const char name[] = "Logger"; + PTHREAD_SETNAME(name); + + auto thman = gMainApp.GetThreadManager(); + thman->RegistThread(this, name); + + // 実行開始。 + std::lock_guard lock_sub(this->thread_starter); + ThreadRun(); +} + // スレッドを終了させる void Logger::TerminateThread() { if ((bool)thread) { + auto thman = gMainApp.GetThreadManager(); + thman->UnregistThread(this); + Terminate(); if (thread->joinable()) {