aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/runtime.c
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2021-09-11 11:48:58 +0900
committerbfredl <bjorn.linse@gmail.com>2022-02-26 14:01:38 +0100
commitb87867e69e94d9784468a126f21c721446f080de (patch)
tree45f10fdbd731df8711eee3cafa1603a45749de05 /src/nvim/runtime.c
parentd0f8f76224f501d919ba6c8a5cd717de76903b34 (diff)
downloadrneovim-b87867e69e94d9784468a126f21c721446f080de.tar.gz
rneovim-b87867e69e94d9784468a126f21c721446f080de.tar.bz2
rneovim-b87867e69e94d9784468a126f21c721446f080de.zip
feat(lua): add proper support of luv threads
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r--src/nvim/runtime.c65
1 files changed, 57 insertions, 8 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 1c04cb16b3..4497e2b055 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -24,6 +24,23 @@
static bool runtime_search_path_valid = false;
static int *runtime_search_path_ref = NULL;
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)
+{
+ 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)
@@ -172,6 +189,17 @@ RuntimeSearchPath runtime_search_path_get_cached(int *ref)
return runtime_search_path;
}
+RuntimeSearchPath copy_runtime_search_path(const RuntimeSearchPath src)
+{
+ RuntimeSearchPath dst = KV_INITIAL_VALUE;
+ for (size_t j = 0; j < kv_size(src); j++) {
+ SearchPathItem src_item = kv_A(src, j);
+ kv_push(dst, ((SearchPathItem){ xstrdup(src_item.path), src_item.after, src_item.has_lua }));
+ }
+
+ return dst;
+}
+
void runtime_search_path_unref(RuntimeSearchPath path, int *ref)
FUNC_ATTR_NONNULL_ALL
{
@@ -302,15 +330,33 @@ ArrayOf(String) runtime_get_named(bool lua, Array pat, bool all)
{
int ref;
RuntimeSearchPath path = runtime_search_path_get_cached(&ref);
- ArrayOf(String) rv = ARRAY_DICT_INIT;
- static char buf[MAXPATHL];
+ ArrayOf(String) rv = runtime_get_named_common(lua, pat, all, path);
+
+ runtime_search_path_unref(path, &ref);
+ return rv;
+}
+
+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();
+ return rv;
+}
+
+ArrayOf(String) runtime_get_named_common(bool lua, Array pat, bool all,
+ RuntimeSearchPath path)
+{
+ 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) {
if (item->has_lua == kNone) {
- size_t size = (size_t)snprintf(buf, sizeof buf, "%s/lua/", item->path);
- item->has_lua = (size < sizeof buf && os_isdir((char_u *)buf)) ? kTrue : kFalse;
+ size_t size = (size_t)snprintf(buf, buf_len, "%s/lua/", item->path);
+ item->has_lua = (size < buf_len && os_isdir((char_u *)buf));
}
if (item->has_lua == kFalse) {
continue;
@@ -320,9 +366,9 @@ ArrayOf(String) runtime_get_named(bool lua, Array pat, bool all)
for (size_t j = 0; j < pat.size; j++) {
Object pat_item = pat.items[j];
if (pat_item.type == kObjectTypeString) {
- size_t size = (size_t)snprintf(buf, sizeof buf, "%s/%s",
+ size_t size = (size_t)snprintf(buf, buf_len, "%s/%s",
item->path, pat_item.data.string.data);
- if (size < sizeof buf) {
+ if (size < buf_len) {
if (os_file_is_readable(buf)) {
ADD(rv, STRING_OBJ(cstr_to_string(buf)));
if (!all) {
@@ -333,9 +379,8 @@ ArrayOf(String) runtime_get_named(bool lua, Array pat, bool all)
}
}
}
-
done:
- runtime_search_path_unref(path, &ref);
+ xfree(buf);
return rv;
}
@@ -569,6 +614,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();
+ runtime_search_path_free(runtime_search_path_thread);
+ runtime_search_path_thread = copy_runtime_search_path(runtime_search_path);
+ runtime_search_path_unlock();
}
}