Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a3466a1
managed Rel
VSadov Jun 6, 2026
6a7d7bf
tweaks to release
VSadov Jun 16, 2026
28f367a
Acquire
VSadov Jun 16, 2026
21518c5
cross-port parts of Release with NativeAOT
VSadov Jun 17, 2026
80e283f
more changes to the acquire path
VSadov Jun 17, 2026
22ab486
more tweaks
VSadov Jun 17, 2026
252c0d6
remove native code
VSadov Jun 17, 2026
470a847
flip isOneShot default
VSadov Jun 17, 2026
5fd1207
refactoring (moved Acquire methods together, removed unnecessary `uns…
VSadov Jun 17, 2026
29ac09a
steer inlining similar to NativeAOT
VSadov Jun 17, 2026
e95bc16
folded in spinning
VSadov Jun 17, 2026
676bb74
more unifying of code shape
VSadov Jun 17, 2026
65231c4
comments better match reality
VSadov Jun 18, 2026
e8538ff
allow threadId that is SBLK_MASK_LOCK_THREADID
VSadov Jun 18, 2026
fe34c7c
do not null-check twice in release.
VSadov Jun 19, 2026
41776d3
couple tweaks
VSadov Jun 22, 2026
60648e1
simpler fast case
VSadov Jun 23, 2026
3058c9f
use compareexchange for pointers
VSadov Jun 23, 2026
051cd0a
current
VSadov Jun 23, 2026
f7d8444
current
VSadov Jun 23, 2026
79c4967
GetMethodTableRef
VSadov Jun 23, 2026
42b9b85
fix release
VSadov Jun 24, 2026
92b2c78
tweak
VSadov Jun 24, 2026
332bee5
remove unused functions
VSadov Jun 24, 2026
f83b00b
port recent tweaks to NativeAOT
VSadov Jun 24, 2026
4f29a08
more unused code
VSadov Jun 24, 2026
f5864b2
inlineable lock enter
VSadov Jun 25, 2026
1bd69fe
reverting to NoInline strategy as in NativeAOT
VSadov Jun 25, 2026
23589e2
separate TryAcquireThinLock
VSadov Jun 26, 2026
fd42487
reconcile the last change with NativeAOT
VSadov Jun 26, 2026
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 @@ -392,6 +392,11 @@ internal static unsafe void CopyConstruct<T>(T* dest, T* src) where T : unmanage
internal static ref byte GetRawData(this object obj) =>
ref Unsafe.As<RawData>(obj).Data;

[DebuggerHidden]
[DebuggerStepThrough]
internal static ref nint GetMethodTableRef(this object obj)
=> ref Unsafe.Subtract(ref Unsafe.As<byte, nint>(ref GetRawData(obj)), 1);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe nuint GetRawObjectDataSize(object obj)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ internal static class ManagedThreadId
// This will be initialized by the runtime.
[ThreadStatic]
private static int t_currentManagedThreadId;

internal static int CurrentManagedThreadIdUnchecked => t_currentManagedThreadId;

public static int Current => t_currentManagedThreadId;
public static int Current
{
get
{
Debug.Assert(t_currentManagedThreadId != 0, "The runtime should have initialized the thread id by now.");
return t_currentManagedThreadId;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,55 +54,31 @@ static Lock GetLockObjectFallback(object obj)
#endregion

#region Public Enter/Exit methods

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Enter(object obj)
{
ObjectHeader.HeaderLockResult result = ObjectHeader.TryAcquireThinLock(obj);
if (result == ObjectHeader.HeaderLockResult.Success)
return;

GetLockObject(obj).Enter();
ObjectHeader.AcquireThinLock(obj);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool TryEnter(object obj)
{
ObjectHeader.HeaderLockResult result = ObjectHeader.TryAcquireThinLock(obj);
if (result == ObjectHeader.HeaderLockResult.Success)
return true;

if (result == ObjectHeader.HeaderLockResult.Failure)
return false;

return GetLockObject(obj).TryEnter();
return ObjectHeader.TryAcquireThinLock(obj);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool TryEnter(object obj, int millisecondsTimeout)
{
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);

ObjectHeader.HeaderLockResult result = ObjectHeader.TryAcquireThinLock(obj);
if (result == ObjectHeader.HeaderLockResult.Success)
return true;

return GetLockObject(obj).TryEnter(millisecondsTimeout);
return ObjectHeader.TryAcquireThinLock(obj, millisecondsTimeout);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Exit(object obj)
{
ArgumentNullException.ThrowIfNull(obj);
ObjectHeader.HeaderLockResult result = ObjectHeader.Release(obj);

if (result == ObjectHeader.HeaderLockResult.Success)
{
return;
}

if (result == ObjectHeader.HeaderLockResult.Failure)
{
throw new SynchronizationLockException();
}

GetLockObject(obj).Exit();
ObjectHeader.Release(obj);
}

// Marked no-inlining to prevent recursive inlining of IsAcquired.
Expand All @@ -122,14 +98,7 @@ public static bool IsEntered(object obj)

internal static void SynchronizedMethodEnter(object obj, ref bool lockTaken)
{
ObjectHeader.HeaderLockResult result = ObjectHeader.TryAcquireThinLock(obj);
if (result == ObjectHeader.HeaderLockResult.Success)
{
lockTaken = true;
return;
}

GetLockObject(obj).Enter();
ObjectHeader.AcquireThinLock(obj);
lockTaken = true;
}

Expand All @@ -139,19 +108,7 @@ internal static void SynchronizedMethodExit(object obj, ref bool lockTaken)
if (!lockTaken)
return;

ObjectHeader.HeaderLockResult result = ObjectHeader.Release(obj);

if (result == ObjectHeader.HeaderLockResult.Success)
{
return;
}

if (result == ObjectHeader.HeaderLockResult.Failure)
{
throw new SynchronizationLockException();
}

GetLockObject(obj).Exit();
ObjectHeader.Release(obj);
}
}
}
Loading