aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lua/stdlib.c3
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/os/fs.c3
-rw-r--r--src/nvim/runtime.c33
4 files changed, 19 insertions, 22 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 6a2aef6683..c2ce899a74 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -474,6 +474,9 @@ static int nlua_stricmp(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread)
{
if (!is_thread) {
+ // TODO(bfredl): some of basic string functions should already be
+ // (or be easy to make) threadsafe
+
// stricmp
lua_pushcfunction(lstate, &nlua_stricmp);
lua_setfield(lstate, -2, "stricmp");
diff --git a/src/nvim/main.c b/src/nvim/main.c
index dfd5e5dbe0..ec64e407b2 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -157,7 +157,7 @@ void early_init(mparm_T *paramp)
eval_init(); // init global variables
init_path(argv0 ? argv0 : "nvim");
init_normal_cmds(); // Init the table of Normal mode commands.
- runtime_search_path_init();
+ runtime_init();
highlight_init();
#ifdef WIN32
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index cca76e175d..daf974ee74 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -64,6 +64,9 @@ void fs_init(void)
uv_mutex_init_recursive(&fs_loop_mutex);
}
+/// TODO(bfredl): some of these operations should
+/// be possible to do the private libuv loop of the
+/// thread, instead of contending the global fs loop
void fs_loop_lock(void)
{
uv_mutex_lock(&fs_loop_mutex);
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 4497e2b055..1ec3e40abe 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -27,21 +27,11 @@ static RuntimeSearchPath runtime_search_path;
static RuntimeSearchPath runtime_search_path_thread;
static uv_mutex_t runtime_search_path_mutex;
-void runtime_search_path_init(void)
+void runtime_init(void)
{
uv_mutex_init(&runtime_search_path_mutex);
}
-void runtime_search_path_lock(void)
-{
- uv_mutex_lock(&runtime_search_path_mutex);
-}
-
-void runtime_search_path_unlock(void)
-{
- uv_mutex_unlock(&runtime_search_path_mutex);
-}
-
/// ":runtime [what] {name}"
void ex_runtime(exarg_T *eap)
{
@@ -330,8 +320,9 @@ ArrayOf(String) runtime_get_named(bool lua, Array pat, bool all)
{
int ref;
RuntimeSearchPath path = runtime_search_path_get_cached(&ref);
+ static char buf[MAXPATHL];
- ArrayOf(String) rv = runtime_get_named_common(lua, pat, all, path);
+ ArrayOf(String) rv = runtime_get_named_common(lua, pat, all, path, buf, sizeof buf);
runtime_search_path_unref(path, &ref);
return rv;
@@ -339,18 +330,19 @@ ArrayOf(String) runtime_get_named(bool lua, Array pat, bool all)
ArrayOf(String) runtime_get_named_thread(bool lua, Array pat, bool all)
{
- runtime_search_path_lock();
- ArrayOf(String) rv = runtime_get_named_common(lua, pat, all, runtime_search_path_thread);
- runtime_search_path_unlock();
+ // TODO(bfredl): avoid contention between multiple worker threads?
+ uv_mutex_lock(&runtime_search_path_mutex);
+ static char buf[MAXPATHL];
+ ArrayOf(String) rv = runtime_get_named_common(lua, pat, all, runtime_search_path_thread,
+ buf, sizeof buf);
+ uv_mutex_unlock(&runtime_search_path_mutex);
return rv;
}
ArrayOf(String) runtime_get_named_common(bool lua, Array pat, bool all,
- RuntimeSearchPath path)
+ RuntimeSearchPath path, char *buf, size_t buf_len)
{
ArrayOf(String) rv = ARRAY_DICT_INIT;
- size_t buf_len = MAXPATHL;
- char *buf = xmalloc(MAXPATHL);
for (size_t i = 0; i < kv_size(path); i++) {
SearchPathItem *item = &kv_A(path, i);
if (lua) {
@@ -380,7 +372,6 @@ ArrayOf(String) runtime_get_named_common(bool lua, Array pat, bool all,
}
}
done:
- xfree(buf);
return rv;
}
@@ -614,10 +605,10 @@ void runtime_search_path_validate(void)
runtime_search_path = runtime_search_path_build();
runtime_search_path_valid = true;
runtime_search_path_ref = NULL; // initially unowned
- runtime_search_path_lock();
+ uv_mutex_lock(&runtime_search_path_mutex);
runtime_search_path_free(runtime_search_path_thread);
runtime_search_path_thread = copy_runtime_search_path(runtime_search_path);
- runtime_search_path_unlock();
+ uv_mutex_unlock(&runtime_search_path_mutex);
}
}