mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #24555 from neovim/backport-23224-to-release-0.9
[Backport release-0.9] refactor(env): remove unused mutex
This commit is contained in:
@@ -175,7 +175,6 @@ bool event_teardown(void)
|
|||||||
/// Needed for unit tests. Must be called after `time_init()`.
|
/// Needed for unit tests. Must be called after `time_init()`.
|
||||||
void early_init(mparm_T *paramp)
|
void early_init(mparm_T *paramp)
|
||||||
{
|
{
|
||||||
env_init();
|
|
||||||
estack_init();
|
estack_init();
|
||||||
cmdline_init();
|
cmdline_init();
|
||||||
eval_init(); // init global variables
|
eval_init(); // init global variables
|
||||||
|
@@ -52,22 +52,6 @@
|
|||||||
// Because `uv_os_getenv` requires allocating, we must manage a map to maintain
|
// Because `uv_os_getenv` requires allocating, we must manage a map to maintain
|
||||||
// the behavior of `os_getenv`.
|
// the behavior of `os_getenv`.
|
||||||
static PMap(cstr_t) envmap = MAP_INIT;
|
static PMap(cstr_t) envmap = MAP_INIT;
|
||||||
static uv_mutex_t mutex;
|
|
||||||
|
|
||||||
void env_init(void)
|
|
||||||
{
|
|
||||||
uv_mutex_init(&mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void os_env_var_lock(void)
|
|
||||||
{
|
|
||||||
uv_mutex_lock(&mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void os_env_var_unlock(void)
|
|
||||||
{
|
|
||||||
uv_mutex_unlock(&mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Like getenv(), but returns NULL if the variable is empty.
|
/// Like getenv(), but returns NULL if the variable is empty.
|
||||||
/// @see os_env_exists
|
/// @see os_env_exists
|
||||||
@@ -79,7 +63,6 @@ const char *os_getenv(const char *name)
|
|||||||
if (name[0] == '\0') {
|
if (name[0] == '\0') {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
uv_mutex_lock(&mutex);
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (pmap_has(cstr_t)(&envmap, name)
|
if (pmap_has(cstr_t)(&envmap, name)
|
||||||
&& !!(e = (char *)pmap_get(cstr_t)(&envmap, name))) {
|
&& !!(e = (char *)pmap_get(cstr_t)(&envmap, name))) {
|
||||||
@@ -105,8 +88,6 @@ const char *os_getenv(const char *name)
|
|||||||
}
|
}
|
||||||
pmap_put(cstr_t)(&envmap, xstrdup(name), e);
|
pmap_put(cstr_t)(&envmap, xstrdup(name), e);
|
||||||
end:
|
end:
|
||||||
// Must do this before ELOG, log.c may call os_setenv.
|
|
||||||
uv_mutex_unlock(&mutex);
|
|
||||||
if (r != 0 && r != UV_ENOENT && r != UV_UNKNOWN) {
|
if (r != 0 && r != UV_ENOENT && r != UV_UNKNOWN) {
|
||||||
ELOG("uv_os_getenv(%s) failed: %d %s", name, r, uv_err_name(r));
|
ELOG("uv_os_getenv(%s) failed: %d %s", name, r, uv_err_name(r));
|
||||||
}
|
}
|
||||||
@@ -158,7 +139,6 @@ int os_setenv(const char *name, const char *value, int overwrite)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
uv_mutex_lock(&mutex);
|
|
||||||
int r;
|
int r;
|
||||||
#ifdef MSWIN
|
#ifdef MSWIN
|
||||||
// libintl uses getenv() for LC_ALL/LANG/etc., so we must use _putenv_s().
|
// libintl uses getenv() for LC_ALL/LANG/etc., so we must use _putenv_s().
|
||||||
@@ -173,8 +153,6 @@ int os_setenv(const char *name, const char *value, int overwrite)
|
|||||||
// Destroy the old map item. Do this AFTER uv_os_setenv(), because `value`
|
// Destroy the old map item. Do this AFTER uv_os_setenv(), because `value`
|
||||||
// could be a previous os_getenv() result.
|
// could be a previous os_getenv() result.
|
||||||
pmap_del2(&envmap, name);
|
pmap_del2(&envmap, name);
|
||||||
// Must do this before ELOG, log.c may call os_setenv.
|
|
||||||
uv_mutex_unlock(&mutex);
|
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
ELOG("uv_os_setenv(%s) failed: %d %s", name, r, uv_err_name(r));
|
ELOG("uv_os_setenv(%s) failed: %d %s", name, r, uv_err_name(r));
|
||||||
}
|
}
|
||||||
@@ -188,11 +166,8 @@ int os_unsetenv(const char *name)
|
|||||||
if (name[0] == '\0') {
|
if (name[0] == '\0') {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uv_mutex_lock(&mutex);
|
|
||||||
pmap_del2(&envmap, name);
|
pmap_del2(&envmap, name);
|
||||||
int r = uv_os_unsetenv(name);
|
int r = uv_os_unsetenv(name);
|
||||||
// Must do this before ELOG, log.c may call os_setenv.
|
|
||||||
uv_mutex_unlock(&mutex);
|
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
ELOG("uv_os_unsetenv(%s) failed: %d %s", name, r, uv_err_name(r));
|
ELOG("uv_os_unsetenv(%s) failed: %d %s", name, r, uv_err_name(r));
|
||||||
}
|
}
|
||||||
@@ -519,10 +494,8 @@ static char *os_homedir(void)
|
|||||||
{
|
{
|
||||||
homedir_buf[0] = NUL;
|
homedir_buf[0] = NUL;
|
||||||
size_t homedir_size = MAXPATHL;
|
size_t homedir_size = MAXPATHL;
|
||||||
uv_mutex_lock(&mutex);
|
|
||||||
// http://docs.libuv.org/en/v1.x/misc.html#c.uv_os_homedir
|
// http://docs.libuv.org/en/v1.x/misc.html#c.uv_os_homedir
|
||||||
int ret_value = uv_os_homedir(homedir_buf, &homedir_size);
|
int ret_value = uv_os_homedir(homedir_buf, &homedir_size);
|
||||||
uv_mutex_unlock(&mutex);
|
|
||||||
if (ret_value == 0 && homedir_size < MAXPATHL) {
|
if (ret_value == 0 && homedir_size < MAXPATHL) {
|
||||||
return homedir_buf;
|
return homedir_buf;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user