[threading] Use a RT signal for abort when possible.
[mono.git] / mono / metadata / monitor.c
index 40a7492213b9cd334ee42a1dd8bde93a71287047..5cb4400b5cfb59f6af266200c2c5c837927f00e4 100644 (file)
@@ -872,6 +872,15 @@ ves_icall_System_Threading_Monitor_Monitor_try_enter_with_atomic_var (MonoObject
        *lockTaken = res == 1;
 }
 
+void
+mono_monitor_enter_v4 (MonoObject *obj, char *lock_taken)
+{
+       if (*lock_taken == 1)
+               mono_raise_exception (mono_get_exception_argument ("lockTaken", "lockTaken is already true"));
+
+       ves_icall_System_Threading_Monitor_Monitor_try_enter_with_atomic_var (obj, INFINITE, lock_taken);
+}
+
 gboolean 
 ves_icall_System_Threading_Monitor_Monitor_test_owner (MonoObject *obj)
 {
@@ -948,7 +957,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;
@@ -956,11 +965,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;
        }
 
@@ -987,7 +996,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;
@@ -995,11 +1004,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;
        }
 
@@ -1032,7 +1041,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;
@@ -1040,11 +1049,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;
        }
 
@@ -1053,7 +1062,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;
        }
        
@@ -1108,7 +1117,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;
        }