From 307733cc0fa864fcb92f4c308a0a27d17552df37 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 6 Dec 2022 08:05:28 -0700 Subject: Let user C-c when waiting for DWARF index finalization In PR gdb/29854, Simon pointed out that it would be good to be able to use C-c when the DWARF cooked index is waiting for finalization. The idea here is to be able to interrupt a command like "break" -- not to stop the finalization process itself, which runs in a worker thread. This patch implements this idea, by changing the index wait functions to, by default, allow a quit. Polling is done, because there doesn't seem to be a better way to interrupt a wait on a std::future. For v2, I realized that the thread compatibility code in thread-pool.h also needed an update. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29854 --- gdbsupport/thread-pool.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gdbsupport') diff --git a/gdbsupport/thread-pool.h b/gdbsupport/thread-pool.h index 013c6ab..cb8696e 100644 --- a/gdbsupport/thread-pool.h +++ b/gdbsupport/thread-pool.h @@ -23,6 +23,7 @@ #include #include #include +#include #if CXX_STD_THREAD #include #include @@ -40,8 +41,19 @@ namespace gdb template using future = std::future; +/* ... and the standard future_status. */ +using future_status = std::future_status; + #else /* CXX_STD_THREAD */ +/* A compatibility enum for std::future_status. This is just the + subset needed by gdb. */ +enum class future_status +{ + ready, + timeout, +}; + /* A compatibility wrapper for std::future. Once and are available in all GCC builds -- should that ever happen -- this can be removed. GCC does not implement threading for @@ -71,6 +83,13 @@ public: void wait () const { } + template + future_status wait_for (const std::chrono::duration &duration) + const + { + return future_status::ready; + } + T get () { return std::move (m_value); } private: @@ -85,6 +104,14 @@ class future { public: void wait () const { } + + template + future_status wait_for (const std::chrono::duration &duration) + const + { + return future_status::ready; + } + void get () { } }; -- cgit v1.1