From 5e569a47031d2a5b94cfadd67d5e76ba4651ac4d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 25 Apr 2023 13:39:28 +0200 Subject: refactor(fs): now it is time to get rid of fs_loop and fs_loop_mutex Here's the headline: when run in sync mode (last argument cb=NULL), these functions don't actually use the uv_loop_t. An earlier version of this patch instead replaced fs_loop with using main_loop.uv on the main thread and luv_loop() on luv worker threads. However this made the code more complicated for no reason. Also arbitrarily, half of these functions would attempt to handle UV_ENOMEM by try_to_free_memory(). This would mostly happen on windows because it needs to allocate a converted WCHAR buffer. This should be a quite rare situation. Your system is pretty much hosed already if you cannot allocate like 50 WCHAR:s. Therefore, take the liberty of simply removing this fallback. In addition, we tried to "recover" from ENOMEM in read()/readv() this way which doesn't make any sense. The read buffer(s) are already allocated at this point. This would also be an issue when using these functions on a worker thread, as try_to_free_memory() is not thread-safe. Currently os_file_is_readable() and os_is_dir() is used by worker threads (as part of nvim__get_runtime(), to implement require from 'rtp' in threads). In the end, these changes makes _all_ os/fs.c functions thread-safe, and we thus don't need to document and maintain a thread-safe subset. --- src/nvim/main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index 657f9c67f2..60390c3c60 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -266,10 +266,6 @@ int main(int argc, char **argv) // `argc` and `argv` are also copied, so that they can be changed. init_params(¶ms, argc, argv); - // Since os_open is called during the init_startuptime, we need to call - // fs_init before it. - fs_init(); - init_startuptime(¶ms); // Need to find "--clean" before actually parsing arguments. @@ -1479,7 +1475,7 @@ static void init_startuptime(mparm_T *paramp) { for (int i = 1; i < paramp->argc - 1; i++) { if (STRICMP(paramp->argv[i], "--startuptime") == 0) { - time_fd = os_fopen(paramp->argv[i + 1], "a"); + time_fd = fopen(paramp->argv[i + 1], "a"); time_start("--- NVIM STARTING ---"); break; } -- cgit