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