Ensure locks are released if exceptions are thrown

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

View file

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

View file

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