Ryujinx/Ryujinx.HLE/HOS/GlobalStateTable.cs

70 lines
1.8 KiB
C#
Raw Normal View History

using Ryujinx.HLE.HOS.Kernel;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS
{
class GlobalStateTable
{
2018-12-01 21:01:59 +01:00
private ConcurrentDictionary<KProcess, IdDictionary> _dictByProcess;
public GlobalStateTable()
{
2018-12-01 21:01:59 +01:00
_dictByProcess = new ConcurrentDictionary<KProcess, IdDictionary>();
}
2018-12-01 21:01:59 +01:00
public bool Add(KProcess process, int id, object data)
{
2018-12-01 21:01:59 +01:00
IdDictionary dict = _dictByProcess.GetOrAdd(process, (key) => new IdDictionary());
2018-12-01 21:01:59 +01:00
return dict.Add(id, data);
}
2018-12-01 21:01:59 +01:00
public int Add(KProcess process, object data)
{
2018-12-01 21:01:59 +01:00
IdDictionary dict = _dictByProcess.GetOrAdd(process, (key) => new IdDictionary());
2018-12-01 21:01:59 +01:00
return dict.Add(data);
}
2018-12-01 21:01:59 +01:00
public object GetData(KProcess process, int id)
{
2018-12-01 21:01:59 +01:00
if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
{
2018-12-01 21:01:59 +01:00
return dict.GetData(id);
}
return null;
}
2018-12-01 21:01:59 +01:00
public T GetData<T>(KProcess process, int id)
{
2018-12-01 21:01:59 +01:00
if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
{
2018-12-01 21:01:59 +01:00
return dict.GetData<T>(id);
}
return default(T);
}
2018-12-01 21:01:59 +01:00
public object Delete(KProcess process, int id)
{
2018-12-01 21:01:59 +01:00
if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
{
2018-12-01 21:01:59 +01:00
return dict.Delete(id);
}
return null;
}
2018-12-01 21:01:59 +01:00
public ICollection<object> DeleteProcess(KProcess process)
{
2018-12-01 21:01:59 +01:00
if (_dictByProcess.TryRemove(process, out IdDictionary dict))
{
2018-12-01 21:01:59 +01:00
return dict.Clear();
}
return null;
}
}
}