Ensure locks are released if exceptions are thrown

This commit is contained in:
Gabriel A 2024-07-06 11:52:42 -03:00
parent 40a1517363
commit 0bdf655e2f
2 changed files with 42 additions and 24 deletions

View file

@ -107,31 +107,44 @@ namespace Ryujinx.Graphics.Vulkan
if (_concurrentWaitUnsupported)
{
AcquireLock();
try
{
FenceHelper.WaitAllIndefinitely(_api, _device, stackalloc Fence[] { _fence });
}
finally
{
ReleaseLock();
}
}
FenceHelper.WaitAllIndefinitely(_api, _device, stackalloc Fence[] { _fence });
if (_concurrentWaitUnsupported)
else
{
ReleaseLock();
FenceHelper.WaitAllIndefinitely(_api, _device, stackalloc Fence[] { _fence });
}
}
public bool IsSignaled()
{
if (_concurrentWaitUnsupported && !TryAcquireLock())
{
return false;
}
bool result = FenceHelper.AllSignaled(_api, _device, stackalloc Fence[] { _fence });
if (_concurrentWaitUnsupported)
{
ReleaseLock();
}
if (!TryAcquireLock())
{
return false;
}
return result;
try
{
return FenceHelper.AllSignaled(_api, _device, stackalloc Fence[] { _fence });
}
finally
{
ReleaseLock();
}
}
else
{
return FenceHelper.AllSignaled(_api, _device, stackalloc Fence[] { _fence });
}
}
public void Dispose()

View file

@ -196,18 +196,23 @@ namespace Ryujinx.Graphics.Vulkan
bool signaled = true;
if (hasTimeout)
try
{
signaled = FenceHelper.AllSignaled(api, device, fences[..fenceCount], timeout);
if (hasTimeout)
{
signaled = FenceHelper.AllSignaled(api, device, fences[..fenceCount], timeout);
}
else
{
FenceHelper.WaitAllIndefinitely(api, device, fences[..fenceCount]);
}
}
else
finally
{
FenceHelper.WaitAllIndefinitely(api, device, fences[..fenceCount]);
}
for (int i = 0; i < fenceCount; i++)
{
fenceHolders[i].PutLock();
for (int i = 0; i < fenceCount; i++)
{
fenceHolders[i].PutLock();
}
}
return signaled;