Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private enum LeaveHelperAction
Yield = 2,
Contention = 3,
Error = 4,
};
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern EnterHelperResult TryEnter_FastPath_WithTimeout(object obj, int timeout);
Expand Down Expand Up @@ -92,6 +92,8 @@ private static bool TryEnter_Slowpath(object obj)
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool TryEnter_Slowpath(object obj, int timeout)
{
ArgumentOutOfRangeException.ThrowIfLessThan(timeout, -1, null);

if (TryEnter_Slowpath(ObjectHandleOnStack.Create(ref obj), timeout) != 0)
{
return true;
Expand Down Expand Up @@ -170,13 +172,12 @@ internal static void ExitIfLockTaken(object obj, ref bool lockTaken)
{
LeaveHelperAction exitBehavior = Exit_FastPath(obj);

if (exitBehavior == LeaveHelperAction.None)
if (exitBehavior != LeaveHelperAction.None)
{
lockTaken = false;
Exit_Slowpath(exitBehavior, obj);
return;
}

Exit_Slowpath(exitBehavior, obj);
lockTaken = false;
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/coreclr/classlibnative/bcltype/objectnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,7 @@ FCIMPL1(FC_BOOL_RET, ObjectNative::Monitor_TryEnter_FastPath, Object* obj)
{
FCALL_CONTRACT;

if (obj->TryEnterObjMonitorSpinHelper())
{
FC_RETURN_BOOL(TRUE);
}
else
{
FC_RETURN_BOOL(FALSE);
}
FC_RETURN_BOOL(obj->TryEnterObjMonitorSpinHelper());
}
FCIMPLEND

Expand Down Expand Up @@ -274,8 +267,7 @@ extern "C" INT32 QCALLTYPE Monitor_TryEnter_Slowpath(QCall::ObjectHandleOnStack

GCX_COOP();

if (timeOut < -1)
COMPlusThrow(kArgumentOutOfRangeException);
_ASSERTE(timeOut >= -1); // This should be checked in managed code.

result = objHandle.Get()->TryEnterObjMonitor(timeOut);

Expand Down
Loading