Typo
[mono.git] / mono / metadata / monitor.c
index 78aa3961027ff5684b3666231e6d94ba3d417a0a..7a409e2d56ef64c38126af7013e59f0ab3b0dcef 100644 (file)
@@ -4,7 +4,8 @@
  * Author:
  *     Dick Porter (dick@ximian.com)
  *
- * (C) 2003 Ximian, Inc.
+ * Copyright 2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
  */
 
 #include <config.h>
@@ -23,6 +24,7 @@
 #include <mono/metadata/debug-helpers.h>
 #include <mono/metadata/tabledefs.h>
 #include <mono/metadata/marshal.h>
+#include <mono/metadata/profiler-private.h>
 #include <mono/utils/mono-time.h>
 
 /*
@@ -102,7 +104,7 @@ static int array_size = 16;
 static __thread gsize tls_pthread_self MONO_TLS_FAST;
 #endif
 
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
 #ifdef HAVE_KW_THREAD
 #define GetCurrentThreadId() tls_pthread_self
 #else
@@ -123,7 +125,30 @@ mono_monitor_init (void)
 void
 mono_monitor_cleanup (void)
 {
+       MonoThreadsSync *mon;
+       /* MonitorArray *marray, *next = NULL; */
+
        /*DeleteCriticalSection (&monitor_mutex);*/
+
+       /* The monitors on the freelist don't have weak links - mark them */
+       for (mon = monitor_freelist; mon; mon = mon->data)
+               mon->wait_list = (gpointer)-1;
+
+       /* FIXME: This still crashes with sgen (async_read.exe) */
+       /*
+       for (marray = monitor_allocated; marray; marray = next) {
+               int i;
+
+               for (i = 0; i < marray->num_monitors; ++i) {
+                       mon = &marray->monitors [i];
+                       if (mon->wait_list != (gpointer)-1)
+                               mono_gc_weak_link_remove (&mon->data);
+               }
+
+               next = marray->next;
+               g_free (marray);
+       }
+       */
 }
 
 /*
@@ -134,7 +159,7 @@ mono_monitor_cleanup (void)
 void
 mono_monitor_init_tls (void)
 {
-#if !defined(PLATFORM_WIN32) && defined(HAVE_KW_THREAD)
+#if !defined(HOST_WIN32) && defined(HAVE_KW_THREAD)
        tls_pthread_self = pthread_self ();
 #endif
 }
@@ -200,7 +225,7 @@ mono_locks_dump (gboolean include_untaken)
 static void 
 mon_finalize (MonoThreadsSync *mon)
 {
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": Finalizing sync %p", mon));
+       LOCK_DEBUG (g_message ("%s: Finalizing sync %p", __func__, mon));
 
        if (mon->entry_sem != NULL) {
                CloseHandle (mon->entry_sem);
@@ -235,6 +260,15 @@ mon_new (gsize id)
                        for (i = 0; i < marray->num_monitors; ++i) {
                                if (marray->monitors [i].data == NULL) {
                                        new = &marray->monitors [i];
+                                       if (new->wait_list) {
+                                               /* Orphaned events left by aborted threads */
+                                               while (new->wait_list) {
+                                                       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d): Closing orphaned event %d", GetCurrentThreadId (), new->wait_list->data));
+                                                       CloseHandle (new->wait_list->data);
+                                                       new->wait_list = g_slist_remove (new->wait_list, new->wait_list->data);
+                                               }
+                                       }
+                                       mono_gc_weak_link_remove (&new->data);
                                        new->data = monitor_freelist;
                                        monitor_freelist = new;
                                }
@@ -246,7 +280,7 @@ mon_new (gsize id)
                /* need to allocate a new array of monitors */
                if (!monitor_freelist) {
                        MonitorArray *last;
-                       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": allocating more monitors: %d", array_size));
+                       LOCK_DEBUG (g_message ("%s: allocating more monitors: %d", __func__, array_size));
                        marray = g_malloc0 (sizeof (MonoArray) + array_size * sizeof (MonoThreadsSync));
                        marray->num_monitors = array_size;
                        array_size *= 2;
@@ -382,10 +416,9 @@ mono_monitor_try_enter_internal (MonoObject *obj, guint32 ms, gboolean allow_int
        guint32 then = 0, now, delta;
        guint32 waitms;
        guint32 ret;
-       MonoThread *thread;
+       MonoInternalThread *thread;
 
-       LOCK_DEBUG (g_message(G_GNUC_PRETTY_FUNCTION
-                 ": (%d) Trying to lock object %p (%d ms)", id, obj, ms));
+       LOCK_DEBUG (g_message("%s: (%d) Trying to lock object %p (%d ms)", __func__, id, obj, ms));
 
        if (G_UNLIKELY (!obj)) {
                mono_raise_exception (mono_get_exception_argument_null ("obj"));
@@ -400,7 +433,7 @@ retry:
                mono_monitor_allocator_lock ();
                mon = mon_new (id);
                if (InterlockedCompareExchangePointer ((gpointer*)&obj->synchronisation, mon, NULL) == NULL) {
-                       mono_gc_weak_link_add (&mon->data, obj);
+                       mono_gc_weak_link_add (&mon->data, obj, FALSE);
                        mono_monitor_allocator_unlock ();
                        /* Successfully locked */
                        return 1;
@@ -415,7 +448,7 @@ retry:
                                lw.sync = mon;
                                lw.lock_word |= LOCK_WORD_FAT_HASH;
                                if (InterlockedCompareExchangePointer ((gpointer*)&obj->synchronisation, lw.sync, oldlw) == oldlw) {
-                                       mono_gc_weak_link_add (&mon->data, obj);
+                                       mono_gc_weak_link_add (&mon->data, obj, FALSE);
                                        mono_monitor_allocator_unlock ();
                                        /* Successfully locked */
                                        return 1;
@@ -454,7 +487,7 @@ retry:
                        lw.sync = mon;
                        lw.lock_word |= LOCK_WORD_FAT_HASH;
                        if (InterlockedCompareExchangePointer ((gpointer*)&obj->synchronisation, lw.sync, oldlw) == oldlw) {
-                               mono_gc_weak_link_add (&mon->data, obj);
+                               mono_gc_weak_link_add (&mon->data, obj, TRUE);
                                mono_monitor_allocator_unlock ();
                                /* Successfully locked */
                                return 1;
@@ -507,13 +540,44 @@ retry:
 
        /* If ms is 0 we don't block, but just fail straight away */
        if (ms == 0) {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) timed out, returning FALSE", id));
+               LOCK_DEBUG (g_message ("%s: (%d) timed out, returning FALSE", __func__, id));
                return 0;
        }
 
-       /* The slow path begins here.  We need to make sure theres a
-        * semaphore handle (creating it if necessary), and block on
-        * it
+       mono_profiler_monitor_event (obj, MONO_PROFILER_MONITOR_CONTENTION);
+
+       /* The slow path begins here. */
+retry_contended:
+       /* a small amount of duplicated code, but it allows us to insert the profiler
+        * callbacks without impacting the fast path: from here on we don't need to go back to the
+        * retry label, but to retry_contended. At this point mon is already installed in the object
+        * header.
+        */
+       /* This case differs from Dice's case 3 because we don't
+        * deflate locks or cache unused lock records
+        */
+       if (G_LIKELY (mon->owner == 0)) {
+               /* Try to install our ID in the owner field, nest
+               * should have been left at 1 by the previous unlock
+               * operation
+               */
+               if (G_LIKELY (InterlockedCompareExchangePointer ((gpointer *)&mon->owner, (gpointer)id, 0) == 0)) {
+                       /* Success */
+                       g_assert (mon->nest == 1);
+                       mono_profiler_monitor_event (obj, MONO_PROFILER_MONITOR_DONE);
+                       return 1;
+               }
+       }
+
+       /* If the object is currently locked by this thread... */
+       if (mon->owner == id) {
+               mon->nest++;
+               mono_profiler_monitor_event (obj, MONO_PROFILER_MONITOR_DONE);
+               return 1;
+       }
+
+       /* We need to make sure there's a semaphore handle (creating it if
+        * necessary), and block on it
         */
        if (mon->entry_sem == NULL) {
                /* Create the semaphore */
@@ -550,7 +614,7 @@ retry:
 
        mono_perfcounters->thread_queue_len++;
        mono_perfcounters->thread_queue_max++;
-       thread = mono_thread_current ();
+       thread = mono_thread_internal_current ();
 
        mono_thread_set_state (thread, ThreadState_WaitSleepJoin);
 
@@ -570,13 +634,12 @@ retry:
                
                if (now < then) {
                        /* The counter must have wrapped around */
-                       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                                  ": wrapped around! now=0x%x then=0x%x", now, then));
+                       LOCK_DEBUG (g_message ("%s: wrapped around! now=0x%x then=0x%x", __func__, now, then));
                        
                        now += (0xffffffff - then);
                        then = 0;
 
-                       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": wrap rejig: now=0x%x then=0x%x delta=0x%x", now, then, now-then));
+                       LOCK_DEBUG (g_message ("%s: wrap rejig: now=0x%x then=0x%x delta=0x%x", __func__, now, then, now-then));
                }
                
                delta = now - then;
@@ -588,29 +651,32 @@ retry:
 
                if ((ret == WAIT_TIMEOUT || (ret == WAIT_IO_COMPLETION && !allow_interruption)) && ms > 0) {
                        /* More time left */
-                       goto retry;
+                       goto retry_contended;
                }
        } else {
                if (ret == WAIT_TIMEOUT || (ret == WAIT_IO_COMPLETION && !allow_interruption)) {
-                       if (ret == WAIT_IO_COMPLETION && mono_thread_test_state (mono_thread_current (), ThreadState_StopRequested)) {
+                       if (ret == WAIT_IO_COMPLETION && (mono_thread_test_state (mono_thread_internal_current (), (ThreadState_StopRequested|ThreadState_SuspendRequested)))) {
                                /* 
-                                * We have to obey a stop request even if allow_interruption is
-                                * FALSE to avoid hangs at shutdown.
+                                * We have to obey a stop/suspend request even if 
+                                * allow_interruption is FALSE to avoid hangs at shutdown.
                                 */
+                               mono_profiler_monitor_event (obj, MONO_PROFILER_MONITOR_FAIL);
                                return -1;
                        }
                        /* Infinite wait, so just try again */
-                       goto retry;
+                       goto retry_contended;
                }
        }
        
        if (ret == WAIT_OBJECT_0) {
                /* retry from the top */
-               goto retry;
+               goto retry_contended;
        }
-       
+
        /* We must have timed out */
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) timed out waiting, returning FALSE", id));
+       LOCK_DEBUG (g_message ("%s: (%d) timed out waiting, returning FALSE", __func__, id));
+
+       mono_profiler_monitor_event (obj, MONO_PROFILER_MONITOR_FAIL);
 
        if (ret == WAIT_IO_COMPLETION)
                return -1;
@@ -636,7 +702,7 @@ mono_monitor_exit (MonoObject *obj)
        MonoThreadsSync *mon;
        guint32 nest;
        
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) Unlocking %p", GetCurrentThreadId (), obj));
+       LOCK_DEBUG (g_message ("%s: (%d) Unlocking %p", __func__, GetCurrentThreadId (), obj));
 
        if (G_UNLIKELY (!obj)) {
                mono_raise_exception (mono_get_exception_argument_null ("obj"));
@@ -665,8 +731,7 @@ mono_monitor_exit (MonoObject *obj)
        
        nest = mon->nest - 1;
        if (nest == 0) {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                         ": (%d) Object %p is now unlocked", GetCurrentThreadId (), obj));
+               LOCK_DEBUG (g_message ("%s: (%d) Object %p is now unlocked", __func__, GetCurrentThreadId (), obj));
        
                /* object is now unlocked, leave nest==1 so we don't
                 * need to set it when the lock is reacquired
@@ -684,12 +749,30 @@ mono_monitor_exit (MonoObject *obj)
                        ReleaseSemaphore (mon->entry_sem, 1, NULL);
                }
        } else {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                         ": (%d) Object %p is now locked %d times", GetCurrentThreadId (), obj, nest));
+               LOCK_DEBUG (g_message ("%s: (%d) Object %p is now locked %d times", __func__, GetCurrentThreadId (), obj, nest));
                mon->nest = nest;
        }
 }
 
+void**
+mono_monitor_get_object_monitor_weak_link (MonoObject *object)
+{
+       LockWord lw;
+       MonoThreadsSync *sync = NULL;
+
+       lw.sync = object->synchronisation;
+       if (lw.lock_word & LOCK_WORD_FAT_HASH) {
+               lw.lock_word &= ~LOCK_WORD_BITS_MASK;
+               sync = lw.sync;
+       } else if (!(lw.lock_word & LOCK_WORD_THIN_HASH)) {
+               sync = lw.sync;
+       }
+
+       if (sync && sync->data)
+               return &sync->data;
+       return NULL;
+}
+
 static void
 emit_obj_syncp_check (MonoMethodBuilder *mb, int syncp_loc, int *obj_null_branch, int *syncp_true_false_branch,
        gboolean branch_on_true)
@@ -788,7 +871,7 @@ mono_monitor_get_fast_enter_method (MonoMethod *monitor_enter_method)
        mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
        mono_mb_emit_byte (mb, CEE_MONO_TLS);
        mono_mb_emit_i4 (mb, thread_tls_offset);
-       mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoThread, tid));
+       mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoInternalThread, tid));
        mono_mb_emit_byte (mb, CEE_ADD);
        mono_mb_emit_byte (mb, CEE_LDIND_I);
        mono_mb_emit_stloc (mb, tid_loc);
@@ -929,7 +1012,7 @@ mono_monitor_get_fast_exit_method (MonoMethod *monitor_exit_method)
        mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
        mono_mb_emit_byte (mb, CEE_MONO_TLS);
        mono_mb_emit_i4 (mb, thread_tls_offset);
-       mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoThread, tid));
+       mono_mb_emit_icon (mb, G_STRUCT_OFFSET (MonoInternalThread, tid));
        mono_mb_emit_byte (mb, CEE_ADD);
        mono_mb_emit_byte (mb, CEE_LDIND_I);
        owned_branch = mono_mb_emit_short_branch (mb, CEE_BEQ_S);
@@ -1040,6 +1123,27 @@ mono_monitor_get_fast_path (MonoMethod *enter_or_exit)
        return NULL;
 }
 
+/*
+ * mono_monitor_threads_sync_member_offset:
+ * @owner_offset: returns size and offset of the "owner" member
+ * @nest_offset: returns size and offset of the "nest" member
+ * @entry_count_offset: returns size and offset of the "entry_count" member
+ *
+ * Returns the offsets and sizes of three members of the
+ * MonoThreadsSync struct.  The Monitor ASM fastpaths need this.
+ */
+void
+mono_monitor_threads_sync_members_offset (int *owner_offset, int *nest_offset, int *entry_count_offset)
+{
+       MonoThreadsSync ts;
+
+#define ENCODE_OFF_SIZE(o,s)   (((o) << 8) | ((s) & 0xff))
+
+       *owner_offset = ENCODE_OFF_SIZE (G_STRUCT_OFFSET (MonoThreadsSync, owner), sizeof (ts.owner));
+       *nest_offset = ENCODE_OFF_SIZE (G_STRUCT_OFFSET (MonoThreadsSync, nest), sizeof (ts.nest));
+       *entry_count_offset = ENCODE_OFF_SIZE (G_STRUCT_OFFSET (MonoThreadsSync, entry_count), sizeof (ts.entry_count));
+}
+
 gboolean 
 ves_icall_System_Threading_Monitor_Monitor_try_enter (MonoObject *obj, guint32 ms)
 {
@@ -1054,13 +1158,26 @@ ves_icall_System_Threading_Monitor_Monitor_try_enter (MonoObject *obj, guint32 m
        return res == 1;
 }
 
+void
+ves_icall_System_Threading_Monitor_Monitor_try_enter_with_atomic_var (MonoObject *obj, guint32 ms, char *lockTaken)
+{
+       gint32 res;
+       do {
+               res = mono_monitor_try_enter_internal (obj, ms, TRUE);
+               /*This means we got interrupted during the wait and didn't got the monitor.*/
+               if (res == -1)
+                       mono_thread_interruption_checkpoint ();
+       } while (res == -1);
+       /*It's safe to do it from here since interruption would happen only on the wrapper.*/
+       *lockTaken = res == 1;
+}
+
 gboolean 
 ves_icall_System_Threading_Monitor_Monitor_test_owner (MonoObject *obj)
 {
        MonoThreadsSync *mon;
        
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                 ": Testing if %p is owned by thread %d", obj, GetCurrentThreadId()));
+       LOCK_DEBUG (g_message ("%s: Testing if %p is owned by thread %d", __func__, obj, GetCurrentThreadId()));
 
        mon = obj->synchronisation;
 #ifdef HAVE_MOVING_COLLECTOR
@@ -1089,8 +1206,7 @@ ves_icall_System_Threading_Monitor_Monitor_test_synchronised (MonoObject *obj)
 {
        MonoThreadsSync *mon;
 
-       LOCK_DEBUG (g_message(G_GNUC_PRETTY_FUNCTION
-                 ": (%d) Testing if %p is owned by any thread", GetCurrentThreadId (), obj));
+       LOCK_DEBUG (g_message("%s: (%d) Testing if %p is owned by any thread", __func__, GetCurrentThreadId (), obj));
        
        mon = obj->synchronisation;
 #ifdef HAVE_MOVING_COLLECTOR
@@ -1124,8 +1240,7 @@ ves_icall_System_Threading_Monitor_Monitor_pulse (MonoObject *obj)
 {
        MonoThreadsSync *mon;
        
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) Pulsing %p", 
-               GetCurrentThreadId (), obj));
+       LOCK_DEBUG (g_message ("%s: (%d) Pulsing %p", __func__, GetCurrentThreadId (), obj));
        
        mon = obj->synchronisation;
 #ifdef HAVE_MOVING_COLLECTOR
@@ -1149,13 +1264,10 @@ ves_icall_System_Threading_Monitor_Monitor_pulse (MonoObject *obj)
                return;
        }
 
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) %d threads waiting",
-                 GetCurrentThreadId (), g_slist_length (mon->wait_list)));
+       LOCK_DEBUG (g_message ("%s: (%d) %d threads waiting", __func__, GetCurrentThreadId (), g_slist_length (mon->wait_list)));
        
        if (mon->wait_list != NULL) {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                         ": (%d) signalling and dequeuing handle %p",
-                         GetCurrentThreadId (), mon->wait_list->data));
+               LOCK_DEBUG (g_message ("%s: (%d) signalling and dequeuing handle %p", __func__, GetCurrentThreadId (), mon->wait_list->data));
        
                SetEvent (mon->wait_list->data);
                mon->wait_list = g_slist_remove (mon->wait_list, mon->wait_list->data);
@@ -1167,8 +1279,7 @@ ves_icall_System_Threading_Monitor_Monitor_pulse_all (MonoObject *obj)
 {
        MonoThreadsSync *mon;
        
-       LOCK_DEBUG (g_message(G_GNUC_PRETTY_FUNCTION ": (%d) Pulsing all %p",
-                 GetCurrentThreadId (), obj));
+       LOCK_DEBUG (g_message("%s: (%d) Pulsing all %p", __func__, GetCurrentThreadId (), obj));
 
        mon = obj->synchronisation;
 #ifdef HAVE_MOVING_COLLECTOR
@@ -1192,13 +1303,10 @@ ves_icall_System_Threading_Monitor_Monitor_pulse_all (MonoObject *obj)
                return;
        }
 
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) %d threads waiting",
-                 GetCurrentThreadId (), g_slist_length (mon->wait_list)));
+       LOCK_DEBUG (g_message ("%s: (%d) %d threads waiting", __func__, GetCurrentThreadId (), g_slist_length (mon->wait_list)));
 
        while (mon->wait_list != NULL) {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                         ": (%d) signalling and dequeuing handle %p",
-                         GetCurrentThreadId (), mon->wait_list->data));
+               LOCK_DEBUG (g_message ("%s: (%d) signalling and dequeuing handle %p", __func__, GetCurrentThreadId (), mon->wait_list->data));
        
                SetEvent (mon->wait_list->data);
                mon->wait_list = g_slist_remove (mon->wait_list, mon->wait_list->data);
@@ -1214,11 +1322,9 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
        guint32 ret;
        gboolean success = FALSE;
        gint32 regain;
-       MonoThread *thread = mono_thread_current ();
+       MonoInternalThread *thread = mono_thread_internal_current ();
 
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION
-                 ": (%d) Trying to wait for %p with timeout %dms",
-                 GetCurrentThreadId (), obj, ms));
+       LOCK_DEBUG (g_message ("%s: (%d) Trying to wait for %p with timeout %dms", __func__, GetCurrentThreadId (), obj, ms));
        
        mon = obj->synchronisation;
 #ifdef HAVE_MOVING_COLLECTOR
@@ -1251,8 +1357,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
                return FALSE;
        }
        
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) queuing handle %p",
-                 GetCurrentThreadId (), event));
+       LOCK_DEBUG (g_message ("%s: (%d) queuing handle %p", __func__, GetCurrentThreadId (), event));
 
        mono_thread_current_check_pending_interrupt ();
        
@@ -1265,8 +1370,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
        mon->nest = 1;
        mono_monitor_exit (obj);
 
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) Unlocked %p lock %p",
-                 GetCurrentThreadId (), obj, mon));
+       LOCK_DEBUG (g_message ("%s: (%d) Unlocked %p lock %p", __func__, GetCurrentThreadId (), obj, mon));
 
        /* There's no race between unlocking mon and waiting for the
         * event, because auto reset events are sticky, and this event
@@ -1281,7 +1385,14 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
        mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
        
        if (mono_thread_interruption_requested ()) {
-               CloseHandle (event);
+               /* 
+                * Can't remove the event from wait_list, since the monitor is not locked by
+                * us. So leave it there, mon_new () will delete it when the mon structure
+                * is placed on the free list.
+                * FIXME: The caller expects to hold the lock after the wait returns, but it
+                * doesn't happen in this case:
+                * http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=97268
+                */
                return FALSE;
        }
 
@@ -1303,8 +1414,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
 
        mon->nest = nest;
 
-       LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) Regained %p lock %p",
-                 GetCurrentThreadId (), obj, mon));
+       LOCK_DEBUG (g_message ("%s: (%d) Regained %p lock %p", __func__, GetCurrentThreadId (), obj, mon));
 
        if (ret == WAIT_TIMEOUT) {
                /* Poll the event again, just in case it was signalled
@@ -1324,12 +1434,10 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
         */
        
        if (ret == WAIT_OBJECT_0) {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) Success",
-                         GetCurrentThreadId ()));
+               LOCK_DEBUG (g_message ("%s: (%d) Success", __func__, GetCurrentThreadId ()));
                success = TRUE;
        } else {
-               LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d) Wait failed, dequeuing handle %p",
-                         GetCurrentThreadId (), event));
+               LOCK_DEBUG (g_message ("%s: (%d) Wait failed, dequeuing handle %p", __func__, GetCurrentThreadId (), event));
                /* No pulse, so we have to remove ourself from the
                 * wait queue
                 */