From a2322470b8d4d3df931b320ad5ae4a429f745975 Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Wed, 16 Oct 2024 14:45:07 +0100 Subject: [PATCH] [*] Win32 Shell Opener: do the main operation outside of the lock [*] Linux IO / AuAsync: always use AU_CO_ROUTINE_SUS_NEVER or bool(false). Fixed dropped IO callbacks. [*] Linux: Added POLLHUP to the blocking read poll. We shouldn't need this. Sockets and pipes set their read side on relevant events. For instance, async connect results in a writable signal, dropped sockets will become signaled under a select, etc. IPC works. Net works. Just gonna add this to the read trigger just in case. --- Include/Aurora/Async/AuFutures.hpp | 12 ++++++------ Source/IO/UNIX/IOSubmit.Linux.cpp | 2 +- Source/Processes/AuOpen.Win32.cpp | 24 +++++++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Include/Aurora/Async/AuFutures.hpp b/Include/Aurora/Async/AuFutures.hpp index a70b749f..26639757 100644 --- a/Include/Aurora/Async/AuFutures.hpp +++ b/Include/Aurora/Async/AuFutures.hpp @@ -746,12 +746,12 @@ namespace std void set_exception(exception_ptr const &) noexcept { } - AU_CO_ROUTINE_SUS_ALWAYS initial_suspend() noexcept + AU_CO_ROUTINE_SUS_NEVER initial_suspend() noexcept { return {}; } - AU_CO_ROUTINE_SUS_ALWAYS final_suspend() noexcept + AU_CO_ROUTINE_SUS_NEVER final_suspend() noexcept { return {}; } @@ -775,12 +775,12 @@ namespace std void set_exception(exception_ptr const &) noexcept { } - AU_CO_ROUTINE_SUS_ALWAYS initial_suspend() noexcept + AU_CO_ROUTINE_SUS_NEVER initial_suspend() noexcept { return {}; } - AU_CO_ROUTINE_SUS_ALWAYS final_suspend() noexcept + AU_CO_ROUTINE_SUS_NEVER final_suspend() noexcept { return {}; } @@ -804,12 +804,12 @@ struct AuVoidTask return {}; } - AU_CO_ROUTINE_SUS_ALWAYS initial_suspend() + AU_CO_ROUTINE_SUS_NEVER initial_suspend() { return {}; } - AU_CO_ROUTINE_SUS_ALWAYS final_suspend() noexcept + AU_CO_ROUTINE_SUS_NEVER final_suspend() noexcept { return {}; } diff --git a/Source/IO/UNIX/IOSubmit.Linux.cpp b/Source/IO/UNIX/IOSubmit.Linux.cpp index 4c948e1d..4e68ad6f 100644 --- a/Source/IO/UNIX/IOSubmit.Linux.cpp +++ b/Source/IO/UNIX/IOSubmit.Linux.cpp @@ -515,7 +515,7 @@ namespace Aurora::IO::UNIX submit.aio_reqprio = 0; submit.aio_fildes = context->GetOrCreateFdPollForBlockingRead(fd); submit.aio_offset = 0; - submit.aio_buf = POLLIN; + submit.aio_buf = POLLIN | POLLHUP; submit.aio_nbytes = 0; if (submit.aio_fildes == -1) diff --git a/Source/Processes/AuOpen.Win32.cpp b/Source/Processes/AuOpen.Win32.cpp index 20c45a36..a6024d8d 100644 --- a/Source/Processes/AuOpen.Win32.cpp +++ b/Source/Processes/AuOpen.Win32.cpp @@ -1,5 +1,5 @@ /*** - Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + Copyright (C) 2021 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuOpen.Win32.cpp Date: 2021-6-12 @@ -28,8 +28,10 @@ namespace Aurora::Processes { try { - for (const auto &[uri, type] : gOpenItems) + while (gOpenItems.size()) { + auto &[uri, type] = gOpenItems[0]; + bool bDirExists {}; bool bFileExists {}; @@ -75,21 +77,29 @@ namespace Aurora::Processes } } + auto u16OpenURI = Locale::ConvertFromUTF8(uri); + auto pOpenType = bDirExists ? L"explore" : L"open"; + + gCondMutex->Unlock(); pShellExecuteW(nullptr, - bDirExists ? L"explore" : L"open", - Locale::ConvertFromUTF8(uri).c_str(), + pOpenType, + u16OpenURI.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + gCondMutex->Lock(); + + // Move all N-1 elements for each N, vs clearing later (requires lock?), vs making a copy of the work (requires another alloc?). + // We can just do ShellExecuteW outside of the lock, and access a locally owned U16-translated string container, without bothering the write side mutex or mutable work container. + // A work queue buffer could solve this, but eh. + gOpenItems.erase(gOpenItems.begin()); } - gOpenItems.clear(); gCondVariable->WaitForSignal(); } catch (...) { - Debug::PrintError(); - AuLogWarn("An error occurred while dispatching a ShellExecute runner frame"); + SysPushErrorCatch("An error occurred while dispatching a ShellExecute runner frame"); } } }