1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-20 08:32:08 +00:00

Avoid potential race

This commit is contained in:
riperiperi 2021-10-07 01:13:51 +01:00
parent c61c1ea898
commit a4956591ec

View file

@ -324,9 +324,27 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <param name="rangeAction">The action to call for each modified range</param>
public void ReregisterRanges(Action<ulong, ulong> rangeAction)
{
ulong currentSync = _context.SyncNumber;
ref var ranges = ref ThreadStaticArray<BufferModifiedRange>.Get();
// Range list must be consistent for this operation.
lock (_lock)
{
if (ranges.Length < Count)
{
Array.Resize(ref ranges, Count);
}
int i = 0;
foreach (BufferModifiedRange range in this)
{
ranges[i++] = range;
}
}
ulong currentSync = _context.SyncNumber;
for (int i = 0; i < Count; i++)
{
BufferModifiedRange range = ranges[i];
if (range.SyncNumber != currentSync)
{
rangeAction(range.Address, range.Size);