diff options
author | pommicket <pommicket@gmail.com> | 2022-12-27 13:13:49 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-27 13:13:49 -0500 |
commit | 1379bfc2bfc8f96215d9187e72ac30dc5c94225f (patch) | |
tree | ce23a710a70172593a97d04a14796bcbb10c1f1e /lsp.c | |
parent | 27b8b36aea3bb5913a600bc7e5b41f68557c2587 (diff) |
fix LSP thread safety
Diffstat (limited to 'lsp.c')
-rw-r--r-- | lsp.c | 32 |
1 files changed, 23 insertions, 9 deletions
@@ -309,15 +309,29 @@ static int lsp_communication_thread(void *data) { } u32 lsp_document_id(LSP *lsp, const char *path) { - u32 *value = str_hash_table_get(&lsp->document_ids, path); - if (!value) { - u32 id = arr_len(lsp->document_data); - value = str_hash_table_insert(&lsp->document_ids, path); - *value = id; - LSPDocumentData *data = arr_addp(lsp->document_data); - data->path = str_dup(path); - } - return *value; + SDL_LockMutex(lsp->document_mutex); + u32 *value = str_hash_table_get(&lsp->document_ids, path); + if (!value) { + u32 id = arr_len(lsp->document_data); + value = str_hash_table_insert(&lsp->document_ids, path); + *value = id; + LSPDocumentData *data = arr_addp(lsp->document_data); + data->path = str_dup(path); + } + u32 id = *value; + SDL_UnlockMutex(lsp->document_mutex); + return id; +} + +const char *lsp_document_path(LSP *lsp, LSPDocumentID document) { + SDL_LockMutex(lsp->document_mutex); + if (document >= arr_len(lsp->document_data)) { + assert(0); + return ""; + } + const char *path = lsp->document_data[document].path; + SDL_UnlockMutex(lsp->document_mutex); + return path; } LSP *lsp_create(const char *root_dir, Language language, const char *analyzer_command) { |