Clean up use_posix_spawn

Switch from a global variable to a real function. Make the value atomic.
Clean up handle_fish_use_posix_spawn_change().
This commit is contained in:
ridiculousfish
2021-05-31 12:34:43 -07:00
parent 50e63d4c04
commit 50c851d10e
3 changed files with 16 additions and 10 deletions

View File

@@ -260,11 +260,18 @@ static void handle_curses_change(const environment_t &vars) {
init_curses(vars);
}
/// Whether to use posix_spawn when possible.
static relaxed_atomic_bool_t g_use_posix_spawn{false};
bool get_use_posix_spawn() { return g_use_posix_spawn; }
static void handle_fish_use_posix_spawn_change(const environment_t &vars) {
// note this defaults to true
auto use_posix_spawn = vars.get(L"fish_use_posix_spawn");
g_use_posix_spawn =
use_posix_spawn.missing_or_empty() ? true : bool_from_string(use_posix_spawn->as_string());
// Note if the variable is missing or empty, we default to true.
if (auto var = vars.get(L"fish_use_posix_spawn")) {
g_use_posix_spawn = var->empty() || bool_from_string(var->as_string());
} else {
g_use_posix_spawn = true;
}
}
/// Allow the user to override the limit on how much data the `read` command will process.
@@ -570,9 +577,6 @@ static void init_locale(const environment_t &vars) {
/// Returns true if we think the terminal supports setting its title.
bool term_supports_setting_title() { return can_set_term_title; }
/// Miscellaneous variables.
bool g_use_posix_spawn = false;
// Limit `read` to 100 MiB (bytes not wide chars) by default. This can be overridden by the
// fish_read_limit variable.
size_t read_byte_limit = 100 * 1024 * 1024;