[exec] limit wait_for_pipers() in interactive use

Related to #1183
This commit is contained in:
Tim Stack 2023-08-27 17:12:29 -07:00
parent eda33d696d
commit 05f9eaf74a
5 changed files with 21 additions and 5 deletions

View File

@ -182,6 +182,15 @@ operator-(const struct timeval& lhs, const struct timeval& rhs)
return diff;
}
inline struct timeval
operator+(const struct timeval& lhs, const struct timeval& rhs)
{
struct timeval retval;
timeradd(&lhs, &rhs, &retval);
return retval;
}
typedef int64_t mstime_t;
inline mstime_t

View File

@ -736,7 +736,7 @@ execute_any(exec_context& ec, const std::string& cmdline_with_mode)
(lnav_data.ld_flags & LNF_HEADLESS || ec.ec_path_stack.size() > 1))
{
rescan_files();
wait_for_pipers();
wait_for_pipers(nonstd::nullopt);
rebuild_indexes_repeatedly();
}
});
@ -833,7 +833,11 @@ execute_init_commands(
}
rescan_files();
wait_for_pipers();
auto deadline = current_timeval()
+ ((lnav_data.ld_flags & LNF_HEADLESS)
? timeval{5, 0}
: timeval{0, 500000});
wait_for_pipers(deadline);
rebuild_indexes_repeatedly();
}
if (dls.dls_rows.size() > 1 && lnav_data.ld_view_stack.size() == 1)

View File

@ -1005,7 +1005,7 @@ gather_pipers()
}
void
wait_for_pipers()
wait_for_pipers(nonstd::optional<timeval> deadline)
{
static const auto MAX_SLEEP_TIME = std::chrono::milliseconds(300);
auto sleep_time = std::chrono::milliseconds(10);
@ -1017,6 +1017,9 @@ wait_for_pipers()
log_debug("all pipers finished");
break;
}
if (deadline && (deadline.value() < current_timeval())) {
break;
}
// Use usleep() since it is defined to be interruptable by a signal.
auto urc = usleep(
std::chrono::duration_cast<std::chrono::microseconds>(sleep_time)

View File

@ -283,6 +283,6 @@ extern const ssize_t ZOOM_COUNT;
bool setup_logline_table(exec_context& ec);
void wait_for_children();
void wait_for_pipers();
void wait_for_pipers(nonstd::optional<timeval> deadline = nonstd::nullopt);
#endif

View File

@ -70,7 +70,7 @@ rebuild_indexes_repeatedly()
}
void
wait_for_pipers()
wait_for_pipers(nonstd::optional<timeval>)
{
}