Merge pull request #1624 from esdrubal/getprocesstimes
[mono.git] / mono / metadata / monitor.c
index f5d1db1ce89b857ee4cf9fe047e52e4f8deb888a..f75606c501039317808607c7bdfaccbfe8930a97 100644 (file)
@@ -662,7 +662,9 @@ retry_contended:
         * We pass TRUE instead of allow_interruption since we have to check for the
         * StopRequested case below.
         */
+       MONO_PREPARE_BLOCKING
        ret = WaitForSingleObjectEx (mon->entry_sem, waitms, TRUE);
+       MONO_FINISH_BLOCKING
 
        mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
        
@@ -957,7 +959,7 @@ ves_icall_System_Threading_Monitor_Monitor_pulse (MonoObject *obj)
                LockWord lw;
                lw.sync = mon;
                if (lw.lock_word & LOCK_WORD_THIN_HASH) {
-                       mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked"));
+                       mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked"));
                        return;
                }
                lw.lock_word &= ~LOCK_WORD_BITS_MASK;
@@ -965,11 +967,11 @@ ves_icall_System_Threading_Monitor_Monitor_pulse (MonoObject *obj)
        }
 #endif
        if (mon == NULL) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked"));
                return;
        }
        if (mon_status_get_owner (mon->status) != mono_thread_info_get_small_id ()) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked by this thread"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked by this thread"));
                return;
        }
 
@@ -996,7 +998,7 @@ ves_icall_System_Threading_Monitor_Monitor_pulse_all (MonoObject *obj)
                LockWord lw;
                lw.sync = mon;
                if (lw.lock_word & LOCK_WORD_THIN_HASH) {
-                       mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked"));
+                       mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked"));
                        return;
                }
                lw.lock_word &= ~LOCK_WORD_BITS_MASK;
@@ -1004,11 +1006,11 @@ ves_icall_System_Threading_Monitor_Monitor_pulse_all (MonoObject *obj)
        }
 #endif
        if (mon == NULL) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked"));
                return;
        }
        if (mon_status_get_owner (mon->status) != mono_thread_info_get_small_id ()) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked by this thread"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked by this thread"));
                return;
        }
 
@@ -1041,7 +1043,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
                LockWord lw;
                lw.sync = mon;
                if (lw.lock_word & LOCK_WORD_THIN_HASH) {
-                       mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked"));
+                       mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked"));
                        return FALSE;
                }
                lw.lock_word &= ~LOCK_WORD_BITS_MASK;
@@ -1049,11 +1051,11 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
        }
 #endif
        if (mon == NULL) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked"));
                return FALSE;
        }
        if (mon_status_get_owner (mon->status) != mono_thread_info_get_small_id ()) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Not locked by this thread"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Not locked by this thread"));
                return FALSE;
        }
 
@@ -1062,7 +1064,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
        
        event = CreateEvent (NULL, FALSE, FALSE, NULL);
        if (event == NULL) {
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Failed to set up wait event"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Failed to set up wait event"));
                return FALSE;
        }
        
@@ -1086,7 +1088,9 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
         * is private to this thread.  Therefore even if the event was
         * signalled before we wait, we still succeed.
         */
+       MONO_PREPARE_BLOCKING
        ret = WaitForSingleObjectEx (event, ms, TRUE);
+       MONO_FINISH_BLOCKING
 
        /* Reset the thread state fairly early, so we don't have to worry
         * about the monitor error checking
@@ -1117,7 +1121,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
                 * SynchronizationLockException
                 */
                CloseHandle (event);
-               mono_raise_exception (mono_get_exception_synchronization_lock ("Failed to regain lock"));
+               mono_set_pending_exception (mono_get_exception_synchronization_lock ("Failed to regain lock"));
                return FALSE;
        }