From 6c4f2622ef875679a02c7318b2e185871df7055a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 2 Feb 2021 18:35:49 -0800 Subject: [PATCH] iothread's notify pipes to use make_autoclose_pipes This allows it to take advantage of the upcoming high-range fd changes. --- src/iothread.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/iothread.cpp b/src/iothread.cpp index 87c20b66b..90f4a7512 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -154,17 +154,14 @@ struct notify_pipes_t { /// \return the (immortal) set of pipes used for notifying of completions. static const notify_pipes_t &get_notify_pipes() { static const notify_pipes_t s_notify_pipes = [] { - int pipes[2] = {0, 0}; - assert_with_errno(pipe(pipes) != -1); - set_cloexec(pipes[0]); - set_cloexec(pipes[1]); - // Mark both ends as non-blocking. - for (int fd : pipes) { - if (make_fd_nonblocking(fd)) { - wperror(L"fcntl"); - } + auto pipes = make_autoclose_pipes({}); + if (!pipes) { + DIE_WITH_ERRNO("Unable to create iothread notify pipes"); } - return notify_pipes_t{pipes[0], pipes[1]}; + // Mark both ends as non-blocking. + if (make_fd_nonblocking(pipes->read.fd())) wperror(L"fcntl"); + if (make_fd_nonblocking(pipes->write.fd())) wperror(L"fcntl"); + return notify_pipes_t{pipes->read.acquire(), pipes->write.acquire()}; }(); return s_notify_pipes; }