summaryrefslogtreecommitdiff
path: root/gdb/run-on-main-thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/run-on-main-thread.c')
-rw-r--r--gdb/run-on-main-thread.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c
index ea633d9d2d0..eb22310f5c0 100644
--- a/gdb/run-on-main-thread.c
+++ b/gdb/run-on-main-thread.c
@@ -20,6 +20,7 @@
#include "run-on-main-thread.h"
#include "ser-event.h"
#if CXX_STD_THREAD
+#include <thread>
#include <mutex>
#endif
#include "gdbsupport/event-loop.h"
@@ -38,6 +39,10 @@ static std::vector<std::function<void ()>> runnables;
static std::mutex runnable_mutex;
+/* The main thread. */
+
+static std::thread::id main_thread;
+
#endif
/* Run all the queued runnables. */
@@ -89,10 +94,25 @@ run_on_main_thread (std::function<void ()> &&func)
serial_event_set (runnable_event);
}
+/* See run-on-main-thread.h. */
+
+bool
+is_main_thread ()
+{
+#if CXX_STD_THREAD
+ return std::this_thread::get_id () == main_thread;
+#else
+ return true;
+#endif
+}
+
void _initialize_run_on_main_thread ();
void
_initialize_run_on_main_thread ()
{
+#if CXX_STD_THREAD
+ main_thread = std::this_thread::get_id ();
+#endif
runnable_event = make_serial_event ();
add_file_handler (serial_event_fd (runnable_event), run_events, nullptr,
"run-on-main-thread");