diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index a8d52be1..a7eb3765 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -389,6 +389,14 @@ namespace Aurora }; + struct LinuxConfig + { + bool bFIODisableBatching { false }; + bool bIOLinuxHasProcIpcPerms { false }; + AuUInt8 uSignalTerminate { 27 }; + AuUInt8 uSignalGAIOWorkerThreadDone { 28 }; + }; + struct RuntimeStartInfo { ConsoleConfig console; @@ -398,9 +406,8 @@ namespace Aurora AuAlignTo<32, FIOConfig> fio; AuAlignTo<64, DebugConfig> debug; AuAlignTo<32, ThreadingConfig> threadingConfig; + AuAlignTo<32, LinuxConfig> linuxConfig; AuAlignTo<32, DummyConfig> padding; - bool bFIODisableBatching { true }; - bool bIOLinuxHasProcIpcPerms { false }; }; /** diff --git a/Source/IO/AuIOHandle.Unix.cpp b/Source/IO/AuIOHandle.Unix.cpp index f2a0dd00..cd639315 100644 --- a/Source/IO/AuIOHandle.Unix.cpp +++ b/Source/IO/AuIOHandle.Unix.cpp @@ -51,10 +51,6 @@ namespace Aurora::IO struct UnixIOHandle final : AFileHandle { bool InitFromPath(HandleCreate create) override; - - bool IsFile() override; - bool IsTTY() override; - bool IsPipe() override; }; bool UnixIOHandle::InitFromPath(HandleCreate create) @@ -176,7 +172,7 @@ namespace Aurora::IO AUKN_SYM bool IsHandleTTY(AuUInt uHandle) { - if ((AuInt)uHandle < 0) + if ((AuSInt)uHandle < 0) { return false; } @@ -188,7 +184,7 @@ namespace Aurora::IO { struct stat st; - if ((AuInt)uHandle < 0) + if ((AuSInt)uHandle < 0) { return false; } @@ -206,7 +202,7 @@ namespace Aurora::IO { struct stat st; - if ((AuInt)uHandle < 0) + if ((AuSInt)uHandle < 0) { return false; } diff --git a/Source/IO/FS/Async.Linux.cpp b/Source/IO/FS/Async.Linux.cpp index a6ccbe99..f826b4cf 100644 --- a/Source/IO/FS/Async.Linux.cpp +++ b/Source/IO/FS/Async.Linux.cpp @@ -272,7 +272,7 @@ namespace Aurora::IO::FS } else { - if (gRuntimeConfig.bFIODisableBatching) + if (gRuntimeConfig.linuxConfig.bFIODisableBatching) { UNIX::SendIOBuffers(); } @@ -329,7 +329,7 @@ namespace Aurora::IO::FS } else { - if (gRuntimeConfig.bFIODisableBatching) + if (gRuntimeConfig.linuxConfig.bFIODisableBatching) { UNIX::SendIOBuffers(); } diff --git a/Source/IO/Net/AuNetResolver.Unix.cpp b/Source/IO/Net/AuNetResolver.Unix.cpp index 53b1feb3..3d382430 100644 --- a/Source/IO/Net/AuNetResolver.Unix.cpp +++ b/Source/IO/Net/AuNetResolver.Unix.cpp @@ -17,7 +17,6 @@ namespace Aurora::IO::Net { - static const auto kMagicSignal = SIGRTMIN + 10 - 6 + 9; static AuList> tlsResolvers; struct ThreadLocalCaughtCompletion : Loop::LSSignalCatcher @@ -35,8 +34,15 @@ namespace Aurora::IO::Net NetResolver *pParent_; }; + // this is beyond dumb and inefficient. i think glibc just creates a singular worker thread and resolves each request in a blocking manner with no mutliplexing + // TODO: we really need to make a general purpose AuAsync IO pool and generic resolver replacer/hooking interface for net services. + static auto GetGAIAsyncIOSignal() + { + return SIGUSR1 + gRuntimeConfig.linuxConfig.uSignalGAIOWorkerThreadDone; + } + ThreadLocalCaughtCompletion::ThreadLocalCaughtCompletion(NetResolver *pParent) : - LSSignalCatcher({kMagicSignal}), + LSSignalCatcher({GetGAIAsyncIOSignal()}), pParent_(pParent) { handles_ = {this->handle, AuStaticCast(this->pParent_->pEvent)->GetHandle()}; @@ -132,7 +138,7 @@ namespace Aurora::IO::Net sigevent event {0}; event.sigev_notify = SIGEV_SIGNAL; - event.sigev_signo = kMagicSignal; + event.sigev_signo = GetGAIAsyncIOSignal(); //event._sigev_un._tid = gettid(); auto pQueue = AuMakeShared(this); @@ -353,6 +359,6 @@ namespace Aurora::IO::Net }; ::sigemptyset(&action.sa_mask); - ::sigaction(kMagicSignal, &action, nullptr); + ::sigaction(GetGAIAsyncIOSignal(), &action, nullptr); } } \ No newline at end of file diff --git a/Source/IO/Net/AuNetStream.Linux.cpp b/Source/IO/Net/AuNetStream.Linux.cpp index a553e637..5dae07b2 100644 --- a/Source/IO/Net/AuNetStream.Linux.cpp +++ b/Source/IO/Net/AuNetStream.Linux.cpp @@ -82,7 +82,7 @@ namespace Aurora::IO::Net } else { - if (gRuntimeConfig.bFIODisableBatching) + if (gRuntimeConfig.linuxConfig.bFIODisableBatching) { UNIX::SendIOBuffers(); } @@ -150,7 +150,7 @@ namespace Aurora::IO::Net } else { - if (gRuntimeConfig.bFIODisableBatching) + if (gRuntimeConfig.linuxConfig.bFIODisableBatching) { UNIX::SendIOBuffers(); } diff --git a/Source/IO/UNIX/FDIpcServer.cpp b/Source/IO/UNIX/FDIpcServer.cpp index ca5da10b..5f948342 100644 --- a/Source/IO/UNIX/FDIpcServer.cpp +++ b/Source/IO/UNIX/FDIpcServer.cpp @@ -459,7 +459,7 @@ namespace Aurora::IO::UNIX if ((platform.uKernelMajor > 5) || ((platform.uKernelMajor == 5) && (platform.uKernelMinor >= 6))) { - gHasProcSyscall = gRuntimeConfig.bIOLinuxHasProcIpcPerms; + gHasProcSyscall = gRuntimeConfig.linuxConfig.bIOLinuxHasProcIpcPerms; } #endif } diff --git a/Source/Threading/Threads/AuOSThread.cpp b/Source/Threading/Threads/AuOSThread.cpp index 7cb48a08..b9fce36b 100644 --- a/Source/Threading/Threads/AuOSThread.cpp +++ b/Source/Threading/Threads/AuOSThread.cpp @@ -68,7 +68,6 @@ namespace Aurora::Threading::Threads static ThreadInfo gDummyThreadInfo; #if defined(AURORA_IS_POSIX_DERIVED) - static const auto kSignalAbort = SIGUSR1 + 69; static void HandleSigAbortThread(int a) { @@ -566,7 +565,7 @@ namespace Aurora::Threading::Threads Exit(true); return; } - AttachSignalKiller(); + this->bSupportsAltKill = true; #endif @@ -747,11 +746,11 @@ namespace Aurora::Threading::Threads #if defined(AURORA_IS_POSIX_DERIVED) struct sigaction action = { - .sa_handler = HandleSigAbortThread - + .sa_handler = HandleSigAbortThread, + .sa_flags = 0 }; ::sigemptyset(&action.sa_mask); - ::sigaction(kSignalAbort, &action, nullptr); + ::sigaction(SIGRTMIN + gRuntimeConfig.linuxConfig.uSignalTerminate, &action, nullptr); #endif } @@ -796,11 +795,6 @@ namespace Aurora::Threading::Threads SetAffinity(this->mask_); AffinityPrioThrottleTickAmendECores(); UpdateName(); - - if (!this->bNotOwned) - { - AttachSignalKiller(); - } } static AuHashMap kNiceMap @@ -1282,12 +1276,13 @@ namespace Aurora::Threading::Threads void OSThread::OSDeatach() { #if defined(AURORA_IS_POSIX_DERIVED) - struct sigaction action = - { - .sa_handler = SIG_DFL - }; - ::sigemptyset(&action.sa_mask); - ::sigaction(kSignalAbort, &action, nullptr); + this->bSupportsAltKill = false; + //struct sigaction action = + //{ + // .sa_handler = SIG_DFL + //}; + //::sigemptyset(&action.sa_mask); + //::sigaction(SIGRTMIN + gRuntimeConfig.linuxConfig.uSignalTerminate, &action, nullptr); #endif } @@ -1417,7 +1412,7 @@ namespace Aurora::Threading::Threads if (this->bSupportsAltKill) { - ::pthread_kill(this->handle_, kSignalAbort); + ::pthread_kill(this->handle_, SIGRTMIN + gRuntimeConfig.linuxConfig.uSignalTerminate); } else { @@ -1464,6 +1459,8 @@ namespace Aurora::Threading::Threads AuxUlibInitialize(); #endif + AttachSignalKiller(); + if (auto pThread = GetThread()) { AuStaticCast(pThread)->MakeMain();