Skip to content
Merged
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
14 changes: 7 additions & 7 deletions Source.Engine/SpatialPartition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public sealed class VoxelTree
SpatialPartitionImpl? _owner;
readonly List<ushort> _availableVisitBits = new(2048);
ushort _nextVisitBit;
readonly ReaderWriterLockSlim _lock = new();
readonly ReaderWriterLockSlim _lock = new(LockRecursionPolicy.SupportsRecursion);

[ThreadStatic] static PartitionVisits? t_visits;

Expand Down Expand Up @@ -803,8 +803,8 @@ public void Shutdown() {
public void InsertIntoTree(ushort hPartition, in Vector3 mins, in Vector3 maxs) {
Debug.Assert(hPartition != PARTITION_INVALID_HANDLE);

bool wasReading = t_visits != null;
if (wasReading) _lock.ExitReadLock();
int readCount = _lock.RecursiveReadCount;
for (int i = 0; i < readCount; i++) _lock.ExitReadLock();

_lock.EnterWriteLock();
try {
Expand Down Expand Up @@ -834,7 +834,7 @@ public void InsertIntoTree(ushort hPartition, in Vector3 mins, in Vector3 maxs)
}
finally {
_lock.ExitWriteLock();
if (wasReading) _lock.EnterReadLock();
for (int i = 0; i < readCount; i++) _lock.EnterReadLock();
}
}

Expand All @@ -844,8 +844,8 @@ public void RemoveFromTree(ushort hPartition) {
int nLevel = Unsafe.Add(ref Unsafe.As<TreeArray<sbyte>, sbyte>(ref info.Level), _treeId);
if (nLevel < 0) return;

bool wasReading = t_visits != null;
if (wasReading) _lock.ExitReadLock();
int readCount = _lock.RecursiveReadCount;
for (int i = 0; i < readCount; i++) _lock.ExitReadLock();

_lock.EnterWriteLock();
try {
Expand All @@ -855,7 +855,7 @@ public void RemoveFromTree(ushort hPartition) {
}
finally {
_lock.ExitWriteLock();
if (wasReading) _lock.EnterReadLock();
for (int i = 0; i < readCount; i++) _lock.EnterReadLock();
}
}

Expand Down
Loading