mirror of
https://github.com/fish-shell/fish-shell
synced 2025-02-13 04:33:33 +00:00
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
This commit is contained in:
parent
fd08b660c0
commit
d5d09c993e
2 changed files with 7 additions and 1 deletions
|
@ -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.
|
||||
|
|
3
src/io.h
3
src/io.h
|
@ -312,6 +312,9 @@ class io_buffer_t {
|
|||
/// running. The fillthread fulfills the corresponding promise when it exits.
|
||||
std::future<void> fillthread_waiter_{};
|
||||
|
||||
/// The item id of our background fillthread fd monitor item.
|
||||
uint64_t item_id_{0};
|
||||
|
||||
/// Lock for appending.
|
||||
std::mutex append_lock_{};
|
||||
|
||||
|
|
Loading…
Reference in a new issue