Skip to content

Commit

Permalink
Delete !FEATURE_SYNCTABLE (dotnet#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas authored Jul 20, 2021
1 parent b3862bf commit 6415571
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
<RuntimeBasePath>..\..\Runtime.Base\src\</RuntimeBasePath>
</PropertyGroup>

<PropertyGroup>
<UseSyncTable>true</UseSyncTable>
<DefineConstants Condition="'$(UseSyncTable)' == 'true'">FEATURE_SYNCTABLE;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<FeaturePortableThreadPool Condition="'$(FeaturePortableThreadPool)' == ''">false</FeaturePortableThreadPool>
<FeaturePortableThreadPool Condition="'$(TargetsUnix)' == 'true'">true</FeaturePortableThreadPool>
Expand Down Expand Up @@ -229,9 +225,9 @@
<Compile Include="System\Threading\Interlocked.cs" />
<Compile Include="System\Threading\LockHolder.cs" />
<Compile Include="System\Threading\Monitor.CoreRT.cs" />
<Compile Include="System\Threading\ObjectHeader.cs" Condition="'$(UseSyncTable)' == 'true'" />
<Compile Include="System\Threading\ObjectHeader.cs" />
<Compile Include="System\Threading\Overlapped.cs" />
<Compile Include="System\Threading\SyncTable.cs" Condition="'$(UseSyncTable)' == 'true'" />
<Compile Include="System\Threading\SyncTable.cs" />
<Compile Include="System\Threading\Thread.CoreRT.cs" />
<Compile Include="System\Threading\ThreadPool.CoreRT.cs" />
<Compile Include="System\Type.CoreRT.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ public static object GetObjectValue(object? obj)
return RuntimeImports.RhCompareObjectContentsAndPadding(o1, o2);
}

#if !FEATURE_SYNCTABLE
private const int HASHCODE_BITS = 26;
private const int MASK_HASHCODE = (1 << HASHCODE_BITS) - 1;
#endif

[ThreadStatic]
private static int t_hashSeed;

Expand All @@ -101,57 +96,9 @@ internal static int GetNewHashCode()

public static unsafe int GetHashCode(object o)
{
#if FEATURE_SYNCTABLE
return ObjectHeader.GetHashCode(o);
#else
if (o == null)
return 0;

fixed (IntPtr* pEEType = &o.m_pEEType)
{
int* pSyncBlockIndex = (int*)((byte*)pEEType - 4); // skipping exactly 4 bytes for the SyncTableEntry (exactly 4 bytes not a pointer size).
int hash = *pSyncBlockIndex & MASK_HASHCODE;

if (hash == 0)
return MakeHashCode(o, pSyncBlockIndex);
else
return hash;
}
#endif
}

#if !FEATURE_SYNCTABLE
private static unsafe int MakeHashCode(Object o, int* pSyncBlockIndex)
{
int hash = GetNewHashCode() & MASK_HASHCODE;

if (hash == 0)
hash = 1;

while (true)
{
int oldIndex = Volatile.Read(ref *pSyncBlockIndex);

int currentHash = oldIndex & MASK_HASHCODE;
if (currentHash != 0)
{
// Someone else set the hash code.
hash = currentHash;
break;
}

int newIndex = oldIndex | hash;

if (Interlocked.CompareExchange(ref *pSyncBlockIndex, newIndex, oldIndex) == oldIndex)
break;
// If we get here someone else modified the header. They may have set the hash code, or maybe some
// other bits. Let's try again.
}

return hash;
}
#endif

public static int OffsetToStringData
{
// This offset is baked in by string indexer intrinsic, so there is no harm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public static partial class Monitor
{
#region Object->Lock/Condition mapping

#if !FEATURE_SYNCTABLE
private static ConditionalWeakTable<object, Lock> s_lockTable = new ConditionalWeakTable<object, Lock>();
private static ConditionalWeakTable<object, Lock>.CreateValueCallback s_createLock = (o) => new Lock();
#endif

private static ConditionalWeakTable<object, Condition> s_conditionTable = new ConditionalWeakTable<object, Condition>();
private static ConditionalWeakTable<object, Condition>.CreateValueCallback s_createCondition = (o) => new Condition(GetLock(o));

Expand All @@ -40,11 +35,7 @@ internal static Lock GetLock(object obj)
Debug.Assert(!(obj is Lock),
"Do not use Monitor.Enter or TryEnter on a Lock instance; use Lock methods directly instead.");

#if FEATURE_SYNCTABLE
return ObjectHeader.GetLockObject(obj);
#else
return s_lockTable.GetValue(obj, s_createLock);
#endif
}

private static Condition GetCondition(object obj)
Expand Down

0 comments on commit 6415571

Please sign in to comment.