#include "run-on-main-thread.h"
#include "ser-event.h"
#if CXX_STD_THREAD
+#include <thread>
#include <mutex>
#endif
#include "gdbsupport/event-loop.h"
static std::mutex runnable_mutex;
+/* The main thread. */
+
+static std::thread::id main_thread;
+
#endif
/* Run all the queued runnables. */
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");
extern void run_on_main_thread (std::function<void ()> &&);
+/* Return true on the main thread. */
+
+extern bool is_main_thread ();
+
#endif /* GDB_RUN_ON_MAIN_THREAD_H */
#include "bt-utils.h"
#include "gdbsupport/buildargv.h"
#include "pager.h"
+#include "run-on-main-thread.h"
void (*deprecated_error_begin_hook) (void);
void
maybe_quit (void)
{
+ if (!is_main_thread ())
+ return;
+
if (sync_quit_force_run)
quit ();