Null notifier to support fishd synchronization, so we can select the

synchronization mechanism at runtime
This commit is contained in:
ridiculousfish
2014-05-14 15:03:44 +08:00
parent 30cfb3e795
commit a73b903df9
5 changed files with 41 additions and 15 deletions

View File

@@ -526,13 +526,3 @@ void env_universal_get_names(wcstring_list_t &lst,
show_unexported);
}
bool synchronizes_via_fishd()
{
if (program_name && ! wcscmp(program_name, L"fishd"))
{
/* fishd always wants to use fishd */
return true;
}
return false;
}

View File

@@ -70,7 +70,4 @@ void env_universal_get_names(wcstring_list_t &list,
*/
void env_universal_barrier();
/* Temporary */
bool synchronizes_via_fishd();
#endif

View File

@@ -1900,8 +1900,18 @@ class universal_notifier_named_pipe_t : public universal_notifier_t
}
};
class universal_notifier_null_t : public universal_notifier_t
{
/* Does nothing! */
};
static universal_notifier_t::notifier_strategy_t fetch_default_strategy_from_environment()
{
if (! synchronizes_via_fishd())
{
return universal_notifier_t::strategy_null;
}
universal_notifier_t::notifier_strategy_t result = universal_notifier_t::strategy_default;
const struct
@@ -1983,6 +1993,9 @@ universal_notifier_t *universal_notifier_t::new_notifier_for_strategy(universal_
case strategy_named_pipe:
return new universal_notifier_named_pipe_t(test_path);
case strategy_null:
return new universal_notifier_null_t();
default:
fprintf(stderr, "Unsupported strategy %d\n", strat);
@@ -2022,3 +2035,23 @@ bool universal_notifier_t::notification_fd_became_readable(int fd)
{
return false;
}
static bool initialize_synchronizes_via_fishd()
{
const char *tmp = getenv("fish_use_fishd");
return tmp != NULL && from_string<bool>(tmp);
}
bool synchronizes_via_fishd()
{
if (program_name && ! wcscmp(program_name, L"fishd"))
{
/* fishd always wants to use fishd */
return true;
}
/* Note that in general we can't change this once it's been set, so we only load it once */
static bool result = initialize_synchronizes_via_fishd();
return result;
}

View File

@@ -302,7 +302,10 @@ class universal_notifier_t
strategy_inotify,
// Strategy that uses notify(3). Simple and efficient, but OS X only.
strategy_notifyd
strategy_notifyd,
// Null notifier, does nothing
strategy_null
};
protected:
@@ -343,6 +346,9 @@ class universal_notifier_t
std::string get_machine_identifier();
bool get_hostname_identifier(std::string *result);
/* Temporary */
bool synchronizes_via_fishd();
/* Environment variable for requesting a particular universal notifier. See fetch_default_strategy_from_environment for names. */
#define UNIVERSAL_NOTIFIER_ENV_NAME "fish_universal_notifier"

View File

@@ -124,7 +124,7 @@ static wint_t readb()
fd_max = maxi(fd_max, notifier_fd);
}
/* Get the suggested delay (possibly none) */
/* Get its suggested delay (possibly none) */
struct timeval tv = {};
const unsigned long usecs_delay = notifier.usec_delay_between_polls();
if (usecs_delay > 0)