diff options
Diffstat (limited to 'src/nvim/log.c')
-rw-r--r-- | src/nvim/log.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/nvim/log.c b/src/nvim/log.c index 3575f49e78..08b6d0483e 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -16,29 +16,49 @@ #define USR_LOG_FILE "$HOME/.nvimlog" +static uv_mutex_t mutex; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "log.c.generated.h" #endif +void log_init(void) +{ + uv_mutex_init(&mutex); +} + +void log_lock(void) +{ + uv_mutex_lock(&mutex); +} + +void log_unlock(void) +{ + uv_mutex_unlock(&mutex); +} + bool do_log(int log_level, const char *func_name, int line_num, bool eol, const char* fmt, ...) FUNC_ATTR_UNUSED { + log_lock(); + bool ret = false; FILE *log_file = open_log_file(); if (log_file == NULL) { - return false; + goto end; } va_list args; va_start(args, fmt); - bool ret = v_do_log_to_file(log_file, log_level, func_name, line_num, eol, + ret = v_do_log_to_file(log_file, log_level, func_name, line_num, eol, fmt, args); va_end(args); if (log_file != stderr && log_file != stdout) { fclose(log_file); } +end: + log_unlock(); return ret; } |