Refactor memory managers to a common base class, consolidate Read() method logic (#6360)
* - add new abstract class `VirtualMemoryManagerBase` - rename `MemoryManagerBase` to `VirtualMemoryManagerRefCountedBase` and derive from `VirtualMemoryManagerBase` - change `AddressSpaceManager`, `HvMemoryManager`, `MemoryManager`, and `MemoryManagerHostMapped` to implement abstract members and use the inherited `void VirtualMemoryManagerBase.Read(TVirtual va, Span<byte> data)` implementation. * move property `AddressSpaceSize` up by the other properties
This commit is contained in:
parent
3924bd1a43
commit
a3a63d4394
6 changed files with 161 additions and 295 deletions
35
src/Ryujinx.Cpu/VirtualMemoryManagerRefCountedBase.cs
Normal file
35
src/Ryujinx.Cpu/VirtualMemoryManagerRefCountedBase.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using Ryujinx.Memory;
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Cpu
|
||||
{
|
||||
public abstract class VirtualMemoryManagerRefCountedBase<TVirtual, TPhysical> : VirtualMemoryManagerBase<TVirtual, TPhysical>, IRefCounted
|
||||
where TVirtual : IBinaryInteger<TVirtual>
|
||||
where TPhysical : IBinaryInteger<TPhysical>
|
||||
{
|
||||
private int _referenceCount;
|
||||
|
||||
public void IncrementReferenceCount()
|
||||
{
|
||||
int newRefCount = Interlocked.Increment(ref _referenceCount);
|
||||
|
||||
Debug.Assert(newRefCount >= 1);
|
||||
}
|
||||
|
||||
public void DecrementReferenceCount()
|
||||
{
|
||||
int newRefCount = Interlocked.Decrement(ref _referenceCount);
|
||||
|
||||
Debug.Assert(newRefCount >= 0);
|
||||
|
||||
if (newRefCount == 0)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void Destroy();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue