public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Move DAP JSON reader to its own thread
@ 2023-12-11 18:54 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-12-11 18:54 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f895e1592d5f4e58776e6a2d7ccdcc028cc5df80
commit f895e1592d5f4e58776e6a2d7ccdcc028cc5df80
Author: Tom Tromey <tromey@adacore.com>
Date: Tue Nov 7 09:23:47 2023 -0700
Move DAP JSON reader to its own thread
This changes the DAP server to move the JSON reader to a new thread.
This is key to implementing request cancellation, as now requests can
be read while an earlier one is being serviced.
Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
Diff:
---
gdb/python/lib/gdb/dap/server.py | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index d865dee31a8..53a0ca7f448 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -60,6 +60,9 @@ class Server:
# DAP client. Writing is done in a separate thread to avoid
# blocking the read loop.
self.write_queue = DAPQueue()
+ # Reading is also done in a separate thread, and a queue of
+ # requests is kept.
+ self.read_queue = DAPQueue()
self.done = False
global _server
_server = self
@@ -111,6 +114,14 @@ class Server:
log("WROTE: <<<" + json.dumps(obj) + ">>>")
self.write_queue.put(obj)
+ # This is run in a separate thread and simply reads requests from
+ # the client and puts them into a queue.
+ def _reader_thread(self):
+ while True:
+ cmd = read_json(self.in_stream)
+ log("READ: <<<" + json.dumps(cmd) + ">>>")
+ self.read_queue.put(cmd)
+
@in_dap_thread
def main_loop(self):
"""The main loop of the DAP server."""
@@ -118,9 +129,9 @@ class Server:
# client, and the thread that reads output from the inferior.
start_thread("output reader", self._read_inferior_output)
start_json_writer(self.out_stream, self.write_queue)
+ start_thread("JSON reader", self._reader_thread)
while not self.done:
- cmd = read_json(self.in_stream)
- log("READ: <<<" + json.dumps(cmd) + ">>>")
+ cmd = self.read_queue.get()
result = self._handle_command(cmd)
self._send_json(result)
events = self.delayed_events
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-11 18:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 18:54 [binutils-gdb] Move DAP JSON reader to its own thread Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).