#include <mono/metadata/assembly.h>
#include <mono/metadata/runtime.h>
#include <mono/metadata/verify-internals.h>
-#include <mono/utils/mono-semaphore.h>
+#include <mono/utils/mono-coop-mutex.h>
+#include <mono/utils/mono-coop-semaphore.h>
#include <mono/utils/mono-error-internals.h>
#include <mono/utils/mono-stack-unwinding.h>
#include <mono/utils/mono-time.h>
#ifndef DISABLE_DEBUGGER_AGENT
-#include <mono/utils/mono-mutex.h>
+#include <mono/utils/mono-os-mutex.h>
#define THREAD_TO_INTERNAL(thread) (thread)->internal_thread
static gboolean debugger_thread_exited;
/* Cond variable used to wait for debugger_thread_exited becoming true */
-static mono_cond_t debugger_thread_exited_cond;
+static MonoCoopCond debugger_thread_exited_cond;
/* Mutex for the cond var above */
-static mono_mutex_t debugger_thread_exited_mutex;
+static MonoCoopMutex debugger_thread_exited_mutex;
static DebuggerProfiler debugger_profiler;
static ReplyPacket reply_packets [128];
int nreply_packets;
-#define dbg_lock() do { \
- MONO_TRY_BLOCKING; \
- mono_mutex_lock (&debug_mutex); \
- MONO_FINISH_TRY_BLOCKING; \
-} while (0)
-
-#define dbg_unlock() mono_mutex_unlock (&debug_mutex)
-static mono_mutex_t debug_mutex;
+#define dbg_lock() mono_coop_mutex_lock (&debug_mutex)
+#define dbg_unlock() mono_coop_mutex_unlock (&debug_mutex)
+static MonoCoopMutex debug_mutex;
static void transport_init (void);
static void transport_connect (const char *address);
void
mono_debugger_agent_init (void)
{
- mono_mutex_init_recursive (&debug_mutex);
+ mono_coop_mutex_init_recursive (&debug_mutex);
if (!agent_config.enabled)
return;
event_requests = g_ptr_array_new ();
- mono_mutex_init (&debugger_thread_exited_mutex);
- mono_cond_init (&debugger_thread_exited_cond, 0);
+ mono_coop_mutex_init (&debugger_thread_exited_mutex);
+ mono_coop_cond_init (&debugger_thread_exited_cond);
mono_profiler_install ((MonoProfiler*)&debugger_profiler, runtime_shutdown);
mono_profiler_set_events (MONO_PROFILE_APPDOMAIN_EVENTS | MONO_PROFILE_THREADS | MONO_PROFILE_ASSEMBLY_EVENTS | MONO_PROFILE_JIT_COMPILATION | MONO_PROFILE_METHOD_EVENTS);
breakpoints_cleanup ();
objrefs_cleanup ();
ids_cleanup ();
-
- mono_mutex_destroy (&debugger_thread_exited_mutex);
- mono_cond_destroy (&debugger_thread_exited_cond);
}
/*
/* Write handshake message */
sprintf (handshake_msg, "DWP-Handshake");
/* Must use try blocking as this can nest into code that runs blocking */
- MONO_TRY_BLOCKING;
+ MONO_PREPARE_BLOCKING;
do {
res = transport_send (handshake_msg, strlen (handshake_msg));
} while (res == -1 && get_last_sock_error () == MONO_EINTR);
- MONO_FINISH_TRY_BLOCKING;
+ MONO_FINISH_BLOCKING;
g_assert (res != -1);
/* Read answer */
- MONO_TRY_BLOCKING;
+ MONO_PREPARE_BLOCKING;
res = transport_recv (buf, strlen (handshake_msg));
- MONO_FINISH_TRY_BLOCKING;
+ MONO_FINISH_BLOCKING;
if ((res != strlen (handshake_msg)) || (memcmp (buf, handshake_msg, strlen (handshake_msg)) != 0)) {
fprintf (stderr, "debugger-agent: DWP handshake failed.\n");
return FALSE;
*/
if (!is_debugger_thread ()) {
do {
- MONO_TRY_BLOCKING;
- mono_mutex_lock (&debugger_thread_exited_mutex);
+ mono_coop_mutex_lock (&debugger_thread_exited_mutex);
if (!debugger_thread_exited)
- mono_cond_wait (&debugger_thread_exited_cond, &debugger_thread_exited_mutex);
- mono_mutex_unlock (&debugger_thread_exited_mutex);
- MONO_FINISH_TRY_BLOCKING;
+ mono_coop_cond_wait (&debugger_thread_exited_cond, &debugger_thread_exited_mutex);
+ mono_coop_mutex_unlock (&debugger_thread_exited_mutex);
} while (!debugger_thread_exited);
}
*/
static gint32 threads_suspend_count;
-static mono_mutex_t suspend_mutex;
+static MonoCoopMutex suspend_mutex;
/* Cond variable used to wait for suspend_count becoming 0 */
-static mono_cond_t suspend_cond;
+static MonoCoopCond suspend_cond;
/* Semaphore used to wait for a thread becoming suspended */
-static MonoSemType suspend_sem;
+static MonoCoopSem suspend_sem;
static void
suspend_init (void)
{
- mono_mutex_init (&suspend_mutex);
- mono_cond_init (&suspend_cond, 0);
- MONO_SEM_INIT (&suspend_sem, 0);
+ mono_coop_mutex_init (&suspend_mutex);
+ mono_coop_cond_init (&suspend_cond);
+ mono_coop_sem_init (&suspend_sem, 0);
}
typedef struct
mono_memory_barrier ();
tls->suspended = TRUE;
- MONO_SEM_POST (&suspend_sem);
+ mono_coop_sem_post (&suspend_sem);
}
}
}
{
mono_loader_lock ();
- MONO_TRY_BLOCKING;
- mono_mutex_lock (&suspend_mutex);
- MONO_FINISH_TRY_BLOCKING;
+ mono_coop_mutex_lock (&suspend_mutex);
suspend_count ++;
mono_g_hash_table_foreach (thread_to_tls, notify_thread, NULL);
}
- mono_mutex_unlock (&suspend_mutex);
+ mono_coop_mutex_unlock (&suspend_mutex);
if (suspend_count == 1)
/*
mono_loader_lock ();
- MONO_TRY_BLOCKING;
- mono_mutex_lock (&suspend_mutex);
- MONO_FINISH_TRY_BLOCKING;
+ mono_coop_mutex_lock (&suspend_mutex);
g_assert (suspend_count > 0);
suspend_count --;
}
/* Signal this even when suspend_count > 0, since some threads might have resume_count > 0 */
- err = mono_cond_broadcast (&suspend_cond);
+ err = mono_coop_cond_broadcast (&suspend_cond);
g_assert (err == 0);
- mono_mutex_unlock (&suspend_mutex);
+ mono_coop_mutex_unlock (&suspend_mutex);
//g_assert (err == 0);
if (suspend_count == 0)
tls = mono_g_hash_table_lookup (thread_to_tls, thread);
g_assert (tls);
-
- MONO_TRY_BLOCKING;
- mono_mutex_lock (&suspend_mutex);
- MONO_FINISH_TRY_BLOCKING;
+
+ mono_coop_mutex_lock (&suspend_mutex);
g_assert (suspend_count > 0);
* Signal suspend_count without decreasing suspend_count, the threads will wake up
* but only the one whose resume_count field is > 0 will be resumed.
*/
- err = mono_cond_broadcast (&suspend_cond);
+ err = mono_coop_cond_broadcast (&suspend_cond);
g_assert (err == 0);
- mono_mutex_unlock (&suspend_mutex);
+ mono_coop_mutex_unlock (&suspend_mutex);
//g_assert (err == 0);
mono_loader_unlock ();
tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
- MONO_TRY_BLOCKING;
- mono_mutex_lock (&suspend_mutex);
- MONO_FINISH_TRY_BLOCKING;
+ mono_coop_mutex_lock (&suspend_mutex);
tls->suspending = FALSE;
tls->really_suspended = TRUE;
if (!tls->suspended) {
tls->suspended = TRUE;
- MONO_SEM_POST (&suspend_sem);
+ mono_coop_sem_post (&suspend_sem);
}
DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer)mono_native_thread_id_get ());
- MONO_TRY_BLOCKING;
while (suspend_count - tls->resume_count > 0) {
- err = mono_cond_wait (&suspend_cond, &suspend_mutex);
+ err = mono_coop_cond_wait (&suspend_cond, &suspend_mutex);
g_assert (err == 0);
}
- MONO_FINISH_TRY_BLOCKING;
tls->suspended = FALSE;
tls->really_suspended = FALSE;
threads_suspend_count --;
- mono_mutex_unlock (&suspend_mutex);
+ mono_coop_mutex_unlock (&suspend_mutex);
DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer)mono_native_thread_id_get ());
nwait = count_threads_to_wait_for ();
if (nwait) {
DEBUG_PRINTF (1, "Waiting for %d(%d) threads to suspend...\n", nwait, nthreads);
- err = MONO_SEM_WAIT (&suspend_sem);
+ err = mono_coop_sem_wait (&suspend_sem, MONO_SEM_FLAGS_NONE);
g_assert (err == 0);
waited = TRUE;
} else {
minfo = mono_debug_lookup_method (method);
if (minfo)
- loc = mono_debug_symfile_lookup_location (minfo, sp->il_offset);
+ loc = mono_debug_method_lookup_location (minfo, sp->il_offset);
if (!loc) {
DEBUG_PRINTF (1, "[%p] No line number info for il offset %x, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset);
minfo = mono_debug_lookup_method (frame->method);
if (minfo && frame->il_offset != -1) {
- MonoDebugSourceLocation *loc = mono_debug_symfile_lookup_location (minfo, frame->il_offset);
+ MonoDebugSourceLocation *loc = mono_debug_method_lookup_location (minfo, frame->il_offset);
if (loc) {
ss_req->last_line = loc->row;
}
mono_set_is_debugger_attached (FALSE);
-
- MONO_TRY_BLOCKING;
- mono_mutex_lock (&debugger_thread_exited_mutex);
+
+ mono_coop_mutex_lock (&debugger_thread_exited_mutex);
debugger_thread_exited = TRUE;
- mono_cond_signal (&debugger_thread_exited_cond);
- mono_mutex_unlock (&debugger_thread_exited_mutex);
- MONO_FINISH_TRY_BLOCKING;
+ mono_coop_cond_signal (&debugger_thread_exited_cond);
+ mono_coop_mutex_unlock (&debugger_thread_exited_mutex);
DEBUG_PRINTF (1, "[dbg] Debugger thread exited.\n");