--- nono/host/hostdevice.cpp 2026/04/29 17:05:11 1.1 +++ nono/host/hostdevice.cpp 2026/04/29 17:05:39 1.1.1.5 @@ -10,12 +10,12 @@ #include "hostdevice.h" #include "scheduler.h" -#include "signalthread.h" // コンストラクタ -HostDevice::HostDevice(const std::string& objname_) - : inherited(objname_) +HostDevice::HostDevice(Device *parent_, uint objid_) + : inherited(objid_) { + parent = parent_; } // デストラクタ @@ -24,9 +24,9 @@ HostDevice::~HostDevice() TerminateThread(); } -// 初期化 +// 動的コンストラクションその2 bool -HostDevice::Init() +HostDevice::Create2() { int fds[2]; int r; @@ -81,22 +81,6 @@ HostDevice::DelOuter(int fd) return kevent_add(kq, fd, EVFILT_READ, EV_DELETE, DATA_FROM_OUTER); } -// シグナルスレッドからのパイプを登録 -int -HostDevice::AddSignal(int rfd, int wfd) -{ - int r; - - r = kevent_add(kq, rfd, EVFILT_READ, EV_ADD, DATA_FROM_SIGNAL); - if (r < 0) { - return r; - } - // シグナルスレッドに登録。 - gSignalThread->AddPipe(wfd); - - return 0; -} - // Listen ソケットを登録 int HostDevice::AddListen(int ls, int action) @@ -104,18 +88,6 @@ HostDevice::AddListen(int ls, int action return kevent_add(kq, ls, EVFILT_READ, action, LISTEN_SOCKET); } -// コールバック先デバイスを設定。 -// -// コールバックはデバイスと関数が両方設定されている時だけ呼び出すので、 -// 設定時は、コールバック関数設定後に SetCallbackDevice() でデバイスを設定、 -// 解除時は、まず SetCallbackDevice(NULL) でデバイスを解除、 -// の順にすること。 -void -HostDevice::SetCallbackDevice(Device *dev_) -{ - dev = dev_; -} - // 受信通知コールバックを設定 void HostDevice::SetRxCallback(DeviceCallback_t func) @@ -134,6 +106,8 @@ HostDevice::SetAcceptCallback(DeviceCall void HostDevice::ThreadRun() { + SetThreadAffinityHint(AffinityClass::Light); + for (; exit_requested == false; ) { struct kevent kev; int r; @@ -188,8 +162,8 @@ HostDevice::Dispatch(int udata) // キューに1個以上データが投入されたら VM に通知 n = Read(); if (n > 0) { - if (dev && rx_func) { - (dev->*rx_func)(); + if (rx_func) { + (parent->*rx_func)(); } } } @@ -225,12 +199,12 @@ HostDevice::putlogn(const char *fmt, ... va_list ap; int len; - uint64 vt = gScheduler->GetVirtTime(); - len = snprintf(buf, sizeof(buf), "%4d.%03d'%03d'%03d %s ", - (int)(vt / 1000 / 1000 / 1000), - (int)((vt / 1000 / 1000) % 1000), - (int)((vt / 1000) % 1000), - (int)(vt % 1000), + uint64 vt = scheduler->GetVirtTime(); + len = snprintf(buf, sizeof(buf), "%4u.%03u'%03u'%03u %s ", + (uint)(vt / 1000 / 1000 / 1000), + (uint)((vt / 1000 / 1000) % 1000), + (uint)((vt / 1000) % 1000), + (uint)(vt % 1000), GetName().c_str()); va_start(ap, fmt);