--- nono/host/hostdevice.cpp 2026/04/29 17:05:11 1.1.1.1 +++ nono/host/hostdevice.cpp 2026/04/29 17:06:02 1.1.1.8 @@ -9,13 +9,16 @@ // #include "hostdevice.h" +#include "config.h" #include "scheduler.h" -#include "signalthread.h" // コンストラクタ -HostDevice::HostDevice(const std::string& objname_) - : inherited(objname_) +HostDevice::HostDevice(Device *parent_, uint objid_, + const std::string& portname_) + : inherited(objid_) { + parent = parent_; + SetPortName(portname_); } // デストラクタ @@ -24,9 +27,9 @@ HostDevice::~HostDevice() TerminateThread(); } -// 初期化 +// 動的コンストラクションその2 bool -HostDevice::Init() +HostDevice::Create2() { int fds[2]; int r; @@ -81,46 +84,33 @@ HostDevice::DelOuter(int fd) return kevent_add(kq, fd, EVFILT_READ, EV_DELETE, DATA_FROM_OUTER); } -// シグナルスレッドからのパイプを登録 +// Listen ソケットを登録 int -HostDevice::AddSignal(int rfd, int wfd) +HostDevice::AddListen(int ls, int action) { - int r; - - r = kevent_add(kq, rfd, EVFILT_READ, EV_ADD, DATA_FROM_SIGNAL); - if (r < 0) { - return r; - } - // シグナルスレッドに登録。 - gSignalThread->AddPipe(wfd); - - return 0; + return kevent_add(kq, ls, EVFILT_READ, action, LISTEN_SOCKET); } -// Listen ソケットを登録 +// Listen ソケットを登録解除。 int -HostDevice::AddListen(int ls, int action) +HostDevice::DelListen(int ls) { - return kevent_add(kq, ls, EVFILT_READ, action, LISTEN_SOCKET); + return kevent_add(kq, ls, EVFILT_READ, EV_DELETE, LISTEN_SOCKET); } -// コールバック先デバイスを設定。 -// -// コールバックはデバイスと関数が両方設定されている時だけ呼び出すので、 -// 設定時は、コールバック関数設定後に SetCallbackDevice() でデバイスを設定、 -// 解除時は、まず SetCallbackDevice(NULL) でデバイスを解除、 -// の順にすること。 +// 受信通知コールバックを解除 void -HostDevice::SetCallbackDevice(Device *dev_) +HostDevice::ResetRxCallback() { - dev = dev_; + rx_func = NULL; } // 受信通知コールバックを設定 void -HostDevice::SetRxCallback(DeviceCallback_t func) +HostDevice::SetRxCallback(DeviceCallback_t func, uint32 arg) { rx_func = func; + rx_arg = arg; } // 着信通知コールバックを設定 @@ -134,6 +124,8 @@ HostDevice::SetAcceptCallback(DeviceCall void HostDevice::ThreadRun() { + SetThreadAffinityHint(AffinityClass::Light); + for (; exit_requested == false; ) { struct kevent kev; int r; @@ -179,8 +171,12 @@ HostDevice::Dispatch(int udata) return; } - // 外部に送信 (継承クラスによる) - Write(buf[0]); + if (__predict_false(buf[0] != PIPE_TX)) { + SelectDriver(false); + } else { + // 外部に送信 (継承クラスによる) + Write(); + } } else if (udata == DATA_FROM_OUTER) { // 外部から着信があった @@ -188,8 +184,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)(rx_arg); } } } @@ -225,12 +221,9 @@ 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), "%16s %s ", + SecToStr(vt).c_str(), GetName().c_str()); va_start(ap, fmt);