xdebug

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit c7ac00f7fc93abd0e1264f0b271e10417ab70756
parent c116df59e703424e5aaba03efeb57f05c974d554
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri, 10 Mar 2023 13:04:20 -0800

improve shutdown handling

- request that all threads to exit
- request long running operations be interrupted
- wait for all threads to exit

Diffstat:
Msrc/xdebug.c | 30++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/xdebug.c b/src/xdebug.c @@ -190,8 +190,6 @@ static void *work_thread(void* arg) { exit(-1); } if (r == 0) { - char statusline[64]; - statusline[0] = 0; timeout = dc_periodic(dc); if (timeout < 100) { timeout = 100; @@ -224,6 +222,18 @@ const char* status_text(uint32_t status) { } } +void debugger_exit(void) { + // tell threads to exit + running = 0; + + // cancel long lived operations + dc_interrupt(dc); + + // wake debugger thread + uint64_t n = 1; + if (write(efd, &n, sizeof(n))) {} +} + void handle_status(void* cookie, uint32_t status) { tui_status_rhs(status_text(status)); } @@ -233,6 +243,10 @@ void handle_line(char *line, unsigned len) { dc_interrupt(dc); return; } + if (!strcmp(line, "quit") || !strcmp(line, "exit")) { + debugger_exit(); + return; + } if (len == 0) { return; } @@ -292,14 +306,14 @@ int main(int argc, char** argv) { return -1; } - while (tui_handle_event(handle_line) == 0) ; - tui_exit(); - return 0; -} + while (running && (tui_handle_event(handle_line) == 0)) ; -void debugger_exit(void) { + debugger_exit(); + + pthread_join(t, NULL); + tui_exit(); - exit(0); + return 0; } void MSG(uint32_t flags, const char* fmt, ...) {