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