From a973fe13cbeb653bc6c7bbd5bdf4925b6538e498 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 12 Mar 2024 14:59:17 -0400 Subject: [PATCH] LibCore: Use Core::System::pipe2 for creating the event loops waking FDs --- .../LibCore/EventLoopImplementationUnix.cpp | 16 ++++------------ .../LibCore/EventLoopImplementationUnix.h | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp b/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp index a4cbe0c3fb3..b10d3c729e0 100644 --- a/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp +++ b/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp @@ -239,15 +239,7 @@ struct ThreadData { if (wake_pipe_fds[1] != -1) close(wake_pipe_fds[1]); -#if defined(SOCK_NONBLOCK) - int rc = pipe2(wake_pipe_fds, O_CLOEXEC); -#else - int rc = pipe(wake_pipe_fds); - fcntl(wake_pipe_fds[0], F_SETFD, FD_CLOEXEC); - fcntl(wake_pipe_fds[1], F_SETFD, FD_CLOEXEC); - -#endif - VERIFY(rc == 0); + wake_pipe_fds = MUST(Core::System::pipe2(O_CLOEXEC)); // The wake pipe informs us of POSIX signals as well as manual calls to wake() VERIFY(poll_fds.size() == 0); @@ -264,14 +256,14 @@ struct ThreadData { // The wake pipe is used to notify another event loop that someone has called wake(), or a signal has been received. // wake() writes 0i32 into the pipe, signals write the signal number (guaranteed non-zero). - int wake_pipe_fds[2] { -1, -1 }; + Array wake_pipe_fds { -1, -1 }; pid_t pid { 0 }; }; } EventLoopImplementationUnix::EventLoopImplementationUnix() - : m_wake_pipe_fds(&ThreadData::the().wake_pipe_fds) + : m_wake_pipe_fds(ThreadData::the().wake_pipe_fds) { } @@ -320,7 +312,7 @@ void EventLoopImplementationUnix::post_event(EventReceiver& receiver, NonnullOwn void EventLoopImplementationUnix::wake() { int wake_event = 0; - MUST(Core::System::write((*m_wake_pipe_fds)[1], { &wake_event, sizeof(wake_event) })); + MUST(Core::System::write(m_wake_pipe_fds[1], { &wake_event, sizeof(wake_event) })); } void EventLoopManagerUnix::wait_for_events(EventLoopImplementation::PumpMode mode) diff --git a/Userland/Libraries/LibCore/EventLoopImplementationUnix.h b/Userland/Libraries/LibCore/EventLoopImplementationUnix.h index d29eb7bef96..cfac423d236 100644 --- a/Userland/Libraries/LibCore/EventLoopImplementationUnix.h +++ b/Userland/Libraries/LibCore/EventLoopImplementationUnix.h @@ -59,7 +59,7 @@ private: int m_exit_code { 0 }; // The wake pipe of this event loop needs to be accessible from other threads. - int (*m_wake_pipe_fds)[2]; + Array& m_wake_pipe_fds; }; }