[MethodImplAttribute(MethodImplOptions.InternalCall)]
extern static void try_enter_with_atomic_var (object obj, int millisecondsTimeout, ref bool lockTaken);
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ extern static void enter_with_atomic_var (object obj, ref bool lockTaken);
+
public static void Enter (object obj, ref bool lockTaken)
{
- TryEnter (obj, Timeout.Infinite, ref lockTaken);
+ enter_with_atomic_var (obj, ref lockTaken);
}
public static void TryEnter (object obj, ref bool lockTaken)
ICALL(MONIT_5, "Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised)
ICALL(MONIT_6, "Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter)
ICALL(MONIT_7, "Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait)
+ICALL(MONIT_10, "enter_with_atomic_var", mono_monitor_enter_v4)
ICALL(MONIT_9, "try_enter_with_atomic_var", ves_icall_System_Threading_Monitor_Monitor_try_enter_with_atomic_var)
ICALL_TYPE(MUTEX, "System.Threading.Mutex", MUTEX_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;
+}
+
+void
+mono_monitor_enter_v4 (MonoObject *obj, char *lock_taken)
{
/* FASTPATH */
#ifdef HAVE_MOVING_COLLECTOR
gsize id = mono_thread_info_get_small_id ();
guint32 new_status, old_status, tmp_status;
- if (G_LIKELY (obj && ms == INFINITE && *lockTaken == 0)) {
+ if (G_LIKELY (obj && *lock_taken == 0)) {
mon = obj->synchronisation;
if (G_LIKELY (mon)) {
tmp_status = InterlockedCompareExchange ((gint32*)&mon->status, new_status, old_status);
if (G_LIKELY (tmp_status == old_status)) {
/* Success */
- *lockTaken = 1;
+ *lock_taken = 1;
g_assert (mon->nest == 1);
return;
}
}
#endif
- 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;
-}
-
-void
-mono_monitor_enter_v4 (MonoObject *obj, char *lock_taken)
-{
if (*lock_taken == 1) {
mono_set_pending_exception (mono_get_exception_argument ("lockTaken", "lockTaken is already true"));
return;