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