2018-11-28 23:18:09 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel;
|
2018-03-19 19:58:46 +01:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
|
|
|
class GlobalStateTable
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
private ConcurrentDictionary<KProcess, IdDictionary> DictByProcess;
|
2018-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
public GlobalStateTable()
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
DictByProcess = new ConcurrentDictionary<KProcess, IdDictionary>();
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public bool Add(KProcess Process, int Id, object Data)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
IdDictionary Dict = DictByProcess.GetOrAdd(Process, (Key) => new IdDictionary());
|
2018-03-19 19:58:46 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
return Dict.Add(Id, Data);
|
2018-03-20 16:18:25 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public int Add(KProcess Process, object Data)
|
2018-03-20 16:18:25 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
IdDictionary Dict = DictByProcess.GetOrAdd(Process, (Key) => new IdDictionary());
|
2018-03-20 16:18:25 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
return Dict.Add(Data);
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public object GetData(KProcess Process, int Id)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (DictByProcess.TryGetValue(Process, out IdDictionary Dict))
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return Dict.GetData(Id);
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public T GetData<T>(KProcess Process, int Id)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (DictByProcess.TryGetValue(Process, out IdDictionary Dict))
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return Dict.GetData<T>(Id);
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public object Delete(KProcess Process, int Id)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (DictByProcess.TryGetValue(Process, out IdDictionary Dict))
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return Dict.Delete(Id);
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public ICollection<object> DeleteProcess(KProcess Process)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (DictByProcess.TryRemove(Process, out IdDictionary Dict))
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return Dict.Clear();
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|