This requires cooperation with the extension languages so the support
is defined here. */
+#if CXX_STD_THREAD
+
+#include <mutex>
+
+/* DAP needs a way to interrupt the main thread, so we added
+ gdb.interrupt. However, as this can run from any thread, we need
+ locking for the current extension language. If threading is not
+ available, DAP will not start.
+
+ This lock is held for accesses to quit_flag, active_ext_lang, and
+ cooperative_sigint_handling_disabled. */
+static std::recursive_mutex ext_lang_mutex;
+
+#endif /* CXX_STD_THREAD */
+
/* This flag tracks quit requests when we haven't called out to an
extension language. it also holds quit requests when we transition to
an extension language that doesn't have cooperative SIGINT handling. */
scoped_disable_cooperative_sigint_handling::scoped_disable_cooperative_sigint_handling ()
{
+#if CXX_STD_THREAD
+ std::lock_guard guard (ext_lang_mutex);
+#endif /* CXX_STD_THREAD */
+
/* Force the active extension language to the GDB scripting
language. This ensures that a previously saved SIGINT is moved
to the quit_flag global, as well as ensures that future SIGINTs
scoped_disable_cooperative_sigint_handling::~scoped_disable_cooperative_sigint_handling ()
{
+#if CXX_STD_THREAD
+ std::lock_guard guard (ext_lang_mutex);
+#endif /* CXX_STD_THREAD */
+
cooperative_sigint_handling_disabled = m_prev_cooperative_sigint_handling_disabled;
restore_active_ext_lang (m_prev_active_ext_lang_state);
}
struct active_ext_lang_state *
set_active_ext_lang (const struct extension_language_defn *now_active)
{
+#if CXX_STD_THREAD
+ std::lock_guard guard (ext_lang_mutex);
+#endif /* CXX_STD_THREAD */
+
#if GDB_SELF_TEST
if (selftests::hook_set_active_ext_lang)
selftests::hook_set_active_ext_lang ();
void
restore_active_ext_lang (struct active_ext_lang_state *previous)
{
+#if CXX_STD_THREAD
+ std::lock_guard guard (ext_lang_mutex);
+#endif /* CXX_STD_THREAD */
+
if (cooperative_sigint_handling_disabled)
{
/* See set_active_ext_lang. */
void
set_quit_flag (void)
{
+#if CXX_STD_THREAD
+ std::lock_guard guard (ext_lang_mutex);
+#endif /* CXX_STD_THREAD */
+
if (active_ext_lang->ops != NULL
&& active_ext_lang->ops->set_quit_flag != NULL)
active_ext_lang->ops->set_quit_flag (active_ext_lang);
int
check_quit_flag (void)
{
+#if CXX_STD_THREAD
+ std::lock_guard guard (ext_lang_mutex);
+#endif /* CXX_STD_THREAD */
+
int result = 0;
for (const struct extension_language_defn *extlang : extension_languages)