From d5d09c993e1c569ec4d5ba4cb24ff706798382eb Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 6 Jan 2021 21:03:49 -0800 Subject: [PATCH] io_buffer_t to explicitly poke its item when closing io_buffer_t is used to buffer output from a command substitution, so we can split it into arguments. Typically io_buffer_t reads from its pipe until it gets EOF and then stops reading. However it may be that the cmdsub ends but EOF is not delivered because the stdout of the cmdsub escaped with a background process. Prior to this change we would wake up every 100 msec (select timeout) to check if the cmdsub is finished. However this 100 msec adds latency if a background process is launched from e.g. fish_prompt. Switch to the new poke() function. Now when the cmdsub is finished, it pokes its item, which explicitly wakes it up. This removes the extra latency. Fixes #7559 --- src/io.cpp | 5 ++++- src/io.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/io.cpp b/src/io.cpp index ccb2a05be..9a8bcc0b0 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -151,13 +151,16 @@ void io_buffer_t::begin_filling(autoclose_fd_t fd) { promise->set_value(); } }; - fd_monitor().add(std::move(item)); + this->item_id_ = fd_monitor().add(std::move(item)); } void io_buffer_t::complete_background_fillthread() { + // Mark that our fillthread is done, then wake it up. ASSERT_IS_MAIN_THREAD(); assert(fillthread_running() && "Should have a fillthread"); + assert(this->item_id_ > 0 && "Should have a valid item ID"); shutdown_fillthread_ = true; + fd_monitor().poke_item(this->item_id_); // Wait for the fillthread to fulfill its promise, and then clear the future so we know we no // longer have one. diff --git a/src/io.h b/src/io.h index a1c9417cd..702954cf6 100644 --- a/src/io.h +++ b/src/io.h @@ -312,6 +312,9 @@ class io_buffer_t { /// running. The fillthread fulfills the corresponding promise when it exits. std::future fillthread_waiter_{}; + /// The item id of our background fillthread fd monitor item. + uint64_t item_id_{0}; + /// Lock for appending. std::mutex append_lock_{};