aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/Common
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-07-17 01:18:31 -0300
committerGitHub <noreply@github.com>2020-07-17 14:18:31 +1000
commit46f8cef6a9e4a305803f1356446e25ce54909130 (patch)
tree9a83d7c69040f451107de17eb032c8345d46ebe3 /Ryujinx.HLE/HOS/Kernel/Common
parent986be200bab9eb890ee1a35a42583ec37efe23d0 (diff)
Fix resource limit reserve taking too long (#1391)
Diffstat (limited to 'Ryujinx.HLE/HOS/Kernel/Common')
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs40
1 files changed, 23 insertions, 17 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs b/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs
index 91501a98..64b964da 100644
--- a/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Common/KResourceLimit.cs
@@ -6,13 +6,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
class KResourceLimit : KAutoObject
{
- private const int Time10SecondsMs = 10000;
+ private const int DefaultTimeoutMs = 10000; // 10s
private readonly long[] _current;
private readonly long[] _limit;
- private readonly long[] _available;
+ private readonly long[] _current2;
- private readonly object _lockObj;
+ private readonly object _lock;
private readonly LinkedList<KThread> _waitingThreads;
@@ -20,11 +20,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
public KResourceLimit(KernelContext context) : base(context)
{
- _current = new long[(int)LimitableResource.Count];
- _limit = new long[(int)LimitableResource.Count];
- _available = new long[(int)LimitableResource.Count];
+ _current = new long[(int)LimitableResource.Count];
+ _limit = new long[(int)LimitableResource.Count];
+ _current2 = new long[(int)LimitableResource.Count];
- _lockObj = new object();
+ _lock = new object();
_waitingThreads = new LinkedList<KThread>();
}
@@ -36,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
public bool Reserve(LimitableResource resource, long amount)
{
- return Reserve(resource, amount, KTimeManager.ConvertMillisecondsToNanoseconds(Time10SecondsMs));
+ return Reserve(resource, amount, KTimeManager.ConvertMillisecondsToNanoseconds(DefaultTimeoutMs));
}
public bool Reserve(LimitableResource resource, long amount, long timeout)
@@ -49,15 +49,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
int index = GetIndex(resource);
- lock (_lockObj)
+ lock (_lock)
{
+ if (_current2[index] >= _limit[index])
+ {
+ return false;
+ }
+
long newCurrent = _current[index] + amount;
- while (newCurrent > _limit[index] && _available[index] + amount <= _limit[index])
+ while (newCurrent > _limit[index] && _current2[index] + amount <= _limit[index])
{
_waitingThreadsCount++;
- KConditionVariable.Wait(KernelContext, _waitingThreads, _lockObj, timeout);
+ KConditionVariable.Wait(KernelContext, _waitingThreads, _lock, timeout);
_waitingThreadsCount--;
@@ -72,6 +77,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
if (newCurrent <= _limit[index])
{
_current[index] = newCurrent;
+ _current2[index] += amount;
success = true;
}
@@ -90,14 +96,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
Release(resource, amount, amount);
}
- public void Release(LimitableResource resource, long usedAmount, long availableAmount)
+ public void Release(LimitableResource resource, long amount, long amount2)
{
int index = GetIndex(resource);
- lock (_lockObj)
+ lock (_lock)
{
- _current [index] -= usedAmount;
- _available[index] -= availableAmount;
+ _current[index] -= amount;
+ _current2[index] -= amount2;
if (_waitingThreadsCount > 0)
{
@@ -110,7 +116,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
int index = GetIndex(resource);
- lock (_lockObj)
+ lock (_lock)
{
return _limit[index] - _current[index];
}
@@ -120,7 +126,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
int index = GetIndex(resource);
- lock (_lockObj)
+ lock (_lock)
{
if (_current[index] <= limit)
{