1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-21 10:42:00 +00:00
Ryujinx/Ryujinx.HLE/HOS/Kernel/Common/KAutoObject.cs
gdkchan 48278905d1
Rewrite scheduler context switch code (#1786)
* Rewrite scheduler context switch code

* Fix race in UnmapIpcRestorePermission

* Fix thread exit issue that could leave the scheduler in a invalid state

* Change context switch method to not wait on guest thread, remove spin wait, use SignalAndWait to pass control

* Remove multi-core setting (it is always on now)

* Re-enable assert

* Remove multicore from default config and schema

* Fix race in KTimeManager
2020-12-09 19:20:05 -03:00

72 lines
No EOL
1.7 KiB
C#

using System.Diagnostics;
using System.Threading;
namespace Ryujinx.HLE.HOS.Kernel.Common
{
class KAutoObject
{
protected KernelContext KernelContext;
private int _referenceCount;
public KAutoObject(KernelContext context)
{
KernelContext = context;
_referenceCount = 1;
}
public virtual KernelResult SetName(string name)
{
if (!KernelContext.AutoObjectNames.TryAdd(name, this))
{
return KernelResult.InvalidState;
}
return KernelResult.Success;
}
public static KernelResult RemoveName(KernelContext context, string name)
{
if (!context.AutoObjectNames.TryRemove(name, out _))
{
return KernelResult.NotFound;
}
return KernelResult.Success;
}
public static KAutoObject FindNamedObject(KernelContext context, string name)
{
if (context.AutoObjectNames.TryGetValue(name, out KAutoObject obj))
{
return obj;
}
return null;
}
public void IncrementReferenceCount()
{
int newRefCount = Interlocked.Increment(ref _referenceCount);
Debug.Assert(newRefCount >= 2);
}
public void DecrementReferenceCount()
{
int newRefCount = Interlocked.Decrement(ref _referenceCount);
Debug.Assert(newRefCount >= 0);
if (newRefCount == 0)
{
Destroy();
}
}
protected virtual void Destroy()
{
}
}
}