[RFC 12/17] Add the ability to stop the event loop

Tom Tromey
2019-02-24T16:52:03Z

gdbserver needs a way to stop the event loop. This patch adds it.

gdb/ChangeLog
2019-02-24 Tom Tromey <tom@tromey.com>

* common/event-loop.h (stop_event_loop): Declare.
* common/event-loop.c (event_looping): New global.
(start_event_loop): Check it.
(stop_event_loop): New function.
---
gdb/ChangeLog | 7 +++++++
gdb/common/event-loop.c | 13 ++++++++++++-
gdb/common/event-loop.h | 5 +++++
3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gdb/common/event-loop.c b/gdb/common/event-loop.c
index a2563414dfd..b8d5b007163 100644
--- a/gdb/common/event-loop.c
+++ b/gdb/common/event-loop.c
@@ -256,6 +256,8 @@ gdb_do_one_event (void)
return 1;
}

+static bool event_looping = true;
+
/* Start up the event loop. This is the entry point to the event loop
from the command loop. */

@@ -266,7 +268,8 @@ start_event_loop ()
the event loop engine. gdb_do_one_event will process one event
for each invocation. It blocks waiting for an event and then
processes it. */
- while (1)
+ event_looping = true;
+ while (event_looping)
{
int result = 0;

@@ -288,6 +291,14 @@ start_event_loop ()
to listen to. So we exit GDB. */
return;
}
+
+/* See event-loop.h. */
+
+void
+stop_event_loop ()
+{
+ event_looping = false;
+}
\f

/* Wrapper function for create_file_handler, so that the caller
diff --git a/gdb/common/event-loop.h b/gdb/common/event-loop.h
index 1eec1ed2cd9..9ace0c46f6c 100644
--- a/gdb/common/event-loop.h
+++ b/gdb/common/event-loop.h
@@ -79,6 +79,11 @@ typedef void (timer_handler_func) (gdb_client_data);
/* Exported functions from event-loop.c */

extern void start_event_loop ();
+
+/* Request that the event loop stop. */
+
+extern void stop_event_loop ();
+
extern int gdb_do_one_event (void);
extern void delete_file_handler (int fd);
extern void add_file_handler (int fd, handler_func *proc,
--
2.17.2