Fix deadlock

This commit is contained in:
2026-02-05 13:03:41 +00:00
parent a62d4a18a8
commit dd474cc38d
2 changed files with 19 additions and 19 deletions

13
TODO.md
View File

@@ -9,11 +9,11 @@ Copyright 2025 Syed Daanish
128M -> 412.0M (expected worst case 2.3G) 128M -> 412.0M (expected worst case 2.3G)
``` ```
* Next few super long boring things to do ## Next few super long boring things to do::
* redo lsp threads such that no mutex needed for any rope stuff (necessary rn) * redo lsp threads such that no mutex needed for any rope stuff (done)
- Also make the classes own the methods in lsp - Also make the classes own the methods in lsp (done)
- This will mean that parsers/renderers and keystrokes will not need to be individually locked - This will mean that parsers/renderers and keystrokes will not need to be individually locked (done)
- And so it will be much faster - And so it will be much faster (done)
- At which point the main thread can also be blocked on user input or lsp responses and still be fast - At which point the main thread can also be blocked on user input or lsp responses and still be fast
* Add a superclass for editor called Window (which can be popup or tiled) (done) * Add a superclass for editor called Window (which can be popup or tiled) (done)
* Add a recursive tiling class for windows (done) * Add a recursive tiling class for windows (done)
@@ -23,6 +23,9 @@ Copyright 2025 Syed Daanish
- Seperate system functions into a class that branches to support local / ssh / server modes. - Seperate system functions into a class that branches to support local / ssh / server modes.
- Even lsp shouldnt be directly controlled because it can branch on local and server modes - Even lsp shouldnt be directly controlled because it can branch on local and server modes
- check wolfSSH stuff for remote editing - check wolfSSH stuff for remote editing
- Thick and thin mode
- thin mode only shares screen diffing over the network - uses server settings / themes
- thick only shared fileio and lsp data with local used for all else - uses local settings / themes
- Redo hooks as a engine of its own. - Redo hooks as a engine of its own.
- And factorize renderer into its own class (and make it just return an array of the render without knowing teh x,y) - And factorize renderer into its own class (and make it just return an array of the render without knowing teh x,y)
- which is just managed by the renderer - which is just managed by the renderer

View File

@@ -95,7 +95,6 @@ struct LSPInstance {
return; return;
} }
json response = *read_lsp_message(); json response = *read_lsp_message();
log("Lsp response: %s", response.dump().c_str());
if (response.contains("result") && if (response.contains("result") &&
response["result"].contains("capabilities")) { response["result"].contains("capabilities")) {
auto &caps = response["result"]["capabilities"]; auto &caps = response["result"]["capabilities"];
@@ -191,11 +190,11 @@ struct LSPInstance {
json shutdown = {{"id", ++last_id}, {"method", "shutdown"}}; json shutdown = {{"id", ++last_id}, {"method", "shutdown"}};
send_raw(shutdown); send_raw(shutdown);
pollfd pfd{stdout_fd, POLLIN, 0}; pollfd pfd{stdout_fd, POLLIN, 0};
poll(&pfd, 1, LSP_TIMEOUT); poll(&pfd, 1, 500);
json exit_msg = {{"method", "exit"}}; json exit_msg = {{"method", "exit"}};
send_raw(exit_msg); send_raw(exit_msg);
int waited = 0; int waited = 0;
while (waited < LSP_TIMEOUT) { while (waited < 100) {
int status; int status;
pid_t res = waitpid(pid, &status, WNOHANG); pid_t res = waitpid(pid, &status, WNOHANG);
if (res == pid) if (res == pid)
@@ -252,22 +251,20 @@ struct LSPInstance {
return true; return true;
} }
void add(Editor *ed) { void add(Editor *ed) {
std::unique_lock lock(lsp::lsp_mutex);
editors.push_back(ed); editors.push_back(ed);
lock.unlock();
ed->lsp.store(this); ed->lsp.store(this);
char *buf = read(ed->root, 0, ed->root->char_count); char *buf = read(ed->root, 0, ed->root->char_count);
std::string text(buf); std::string text(buf);
free(buf); free(buf);
auto message = std::make_unique<LSPMessage>(); json message = {{"jsonrpc", "2.0"},
message->message = {{"method", "textDocument/didOpen"}, {"method", "textDocument/didOpen"},
{"params", {"params",
{{"textDocument", {{"textDocument",
{{"uri", ed->uri}, {{"uri", ed->uri},
{"languageId", ed->lang.name}, {"languageId", ed->lang.name},
{"version", 1}, {"version", 1},
{"text", text}}}}}}; {"text", text}}}}}};
send(std::move(message)); send_raw(message);
} }
void remove(Editor *ed) { void remove(Editor *ed) {
std::unique_lock lock(lsp::lsp_mutex); std::unique_lock lock(lsp::lsp_mutex);