Merge branch '1.12.3' into patch-notes
This commit is contained in:
@@ -208,7 +208,13 @@ public unsafe class NameplateHandler : IMediatorSubscriber
|
||||
|
||||
for (int i = 0; i < ui3DModule->NamePlateObjectInfoCount; ++i)
|
||||
{
|
||||
var objectInfo = ui3DModule->NamePlateObjectInfoPointers[i].Value;
|
||||
if (ui3DModule->NamePlateObjectInfoPointers.IsEmpty) continue;
|
||||
|
||||
var objectInfoPtr = ui3DModule->NamePlateObjectInfoPointers[i];
|
||||
|
||||
if (objectInfoPtr == null) continue;
|
||||
|
||||
var objectInfo = objectInfoPtr.Value;
|
||||
|
||||
if (objectInfo == null || objectInfo->GameObject == null)
|
||||
continue;
|
||||
|
||||
@@ -15,6 +15,7 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
private readonly SemaphoreSlim _semaphore;
|
||||
private int _currentLimit;
|
||||
private int _pendingReductions;
|
||||
private int _pendingIncrements;
|
||||
private int _waiting;
|
||||
private int _inFlight;
|
||||
|
||||
@@ -70,7 +71,7 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
|
||||
if (!IsEnabled)
|
||||
{
|
||||
_semaphore.Release();
|
||||
TryReleaseSemaphore();
|
||||
return NoopReleaser.Instance;
|
||||
}
|
||||
|
||||
@@ -90,18 +91,12 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
var releaseAmount = HardLimit - _semaphore.CurrentCount;
|
||||
if (releaseAmount > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
_semaphore.Release(releaseAmount);
|
||||
}
|
||||
catch (SemaphoreFullException)
|
||||
{
|
||||
// ignore, already at max
|
||||
}
|
||||
TryReleaseSemaphore(releaseAmount);
|
||||
}
|
||||
|
||||
_currentLimit = desiredLimit;
|
||||
_pendingReductions = 0;
|
||||
_pendingIncrements = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,10 +108,13 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
if (desiredLimit > _currentLimit)
|
||||
{
|
||||
var increment = desiredLimit - _currentLimit;
|
||||
var allowed = Math.Min(increment, HardLimit - _semaphore.CurrentCount);
|
||||
if (allowed > 0)
|
||||
_pendingIncrements += increment;
|
||||
|
||||
var available = HardLimit - _semaphore.CurrentCount;
|
||||
var toRelease = Math.Min(_pendingIncrements, available);
|
||||
if (toRelease > 0 && TryReleaseSemaphore(toRelease))
|
||||
{
|
||||
_semaphore.Release(allowed);
|
||||
_pendingIncrements -= toRelease;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -133,6 +131,13 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
{
|
||||
_pendingReductions += remaining;
|
||||
}
|
||||
|
||||
if (_pendingIncrements > 0)
|
||||
{
|
||||
var offset = Math.Min(_pendingIncrements, _pendingReductions);
|
||||
_pendingIncrements -= offset;
|
||||
_pendingReductions -= offset;
|
||||
}
|
||||
}
|
||||
|
||||
_currentLimit = desiredLimit;
|
||||
@@ -146,6 +151,25 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
return Math.Clamp(configured, 1, HardLimit);
|
||||
}
|
||||
|
||||
private bool TryReleaseSemaphore(int count = 1)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_semaphore.Release(count);
|
||||
return true;
|
||||
}
|
||||
catch (SemaphoreFullException ex)
|
||||
{
|
||||
Logger.LogDebug(ex, "Attempted to release {count} pair processing slots but semaphore is already at the hard limit.", count);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseOne()
|
||||
{
|
||||
var inFlight = Interlocked.Decrement(ref _inFlight);
|
||||
@@ -166,9 +190,20 @@ public sealed class PairProcessingLimiter : DisposableMediatorSubscriberBase
|
||||
_pendingReductions--;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pendingIncrements > 0)
|
||||
{
|
||||
if (!TryReleaseSemaphore())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pendingIncrements--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_semaphore.Release();
|
||||
TryReleaseSemaphore();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
Reference in New Issue
Block a user