mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-20 17:51:13 +02:00
General memory improvements to decrease GC pressure and frequency. Pool big arrays and objects that are created and deleted often. Skip data copies when they aren't needed. Inline flag checks to skip unneeded allocations. From my testing the performance is about the same, but the GC frequency is much lower and collection is faster causing less and smaller spikes.
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using Ryujinx.Common;
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Common
|
|
{
|
|
class KSynchronizationObject : KAutoObject
|
|
{
|
|
private static readonly ObjectPool<LinkedListNode<KThread>> _nodePool = new(() => new LinkedListNode<KThread>(null));
|
|
|
|
public LinkedList<KThread> WaitingThreads { get; }
|
|
|
|
public KSynchronizationObject(KernelContext context) : base(context)
|
|
{
|
|
WaitingThreads = [];
|
|
}
|
|
|
|
public LinkedListNode<KThread> AddWaitingThread(KThread thread)
|
|
{
|
|
LinkedListNode<KThread> node = _nodePool.Allocate();
|
|
node.Value = thread;
|
|
WaitingThreads.AddLast(node);
|
|
return node;
|
|
}
|
|
|
|
public void RemoveWaitingThread(LinkedListNode<KThread> node)
|
|
{
|
|
WaitingThreads.Remove(node);
|
|
_nodePool.Release(node);
|
|
}
|
|
|
|
public virtual void Signal()
|
|
{
|
|
KernelContext.Synchronization.SignalObject(this);
|
|
}
|
|
|
|
public virtual bool IsSignaled()
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|