From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: "Kévin Le Gouguec" <legouguec@adacore.com>
Subject: [PATCH v2 2/6] Move DAP JSON reader to its own thread
Date: Mon, 11 Dec 2023 09:02:19 -0700 [thread overview]
Message-ID: <20231211-dap-cancel-v2-2-db7b52cf0329@adacore.com> (raw)
In-Reply-To: <20231211-dap-cancel-v2-0-db7b52cf0329@adacore.com>
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>
---
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
--
2.43.0
next prev parent reply other threads:[~2023-12-11 16:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 16:02 [PATCH v2 0/6] Implement DAP cancellation Tom Tromey
2023-12-11 16:02 ` [PATCH v2 1/6] Clean up handling of DAP not-stopped response Tom Tromey
2023-12-11 16:02 ` Tom Tromey [this message]
2023-12-11 16:02 ` [PATCH v2 3/6] Introduce gdb.interrupt Tom Tromey
2023-12-11 16:30 ` Eli Zaretskii
2023-12-11 16:02 ` [PATCH v2 4/6] Rename a couple of DAP procs in the testsuite Tom Tromey
2023-12-11 16:02 ` [PATCH v2 5/6] Catch KeyboardInterrupt in send_gdb_with_response Tom Tromey
2023-12-11 17:53 ` Kévin Le Gouguec
2023-12-11 16:02 ` [PATCH v2 6/6] Implement DAP cancellation Tom Tromey
2023-12-11 18:53 ` [PATCH v2 0/6] " Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231211-dap-cancel-v2-2-db7b52cf0329@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=legouguec@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).