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-17 00:47:36 +01:00
|
|
|
namespace Ryujinx.HLE.HOS
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
|
|
|
class GlobalStateTable
|
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
private ConcurrentDictionary<KProcess, IdDictionary> _dictByProcess;
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
public GlobalStateTable()
|
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
_dictByProcess = new ConcurrentDictionary<KProcess, IdDictionary>();
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
public bool Add(KProcess process, int id, object data)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
IdDictionary dict = _dictByProcess.GetOrAdd(process, (key) => new IdDictionary());
|
2018-03-19 18:58:46 +00:00
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
return dict.Add(id, data);
|
2018-03-20 15:18:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
public int Add(KProcess process, object data)
|
2018-03-20 15:18:25 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
IdDictionary dict = _dictByProcess.GetOrAdd(process, (key) => new IdDictionary());
|
2018-03-20 15:18:25 +00:00
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
return dict.Add(data);
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
public object GetData(KProcess process, int id)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
return dict.GetData(id);
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
public T GetData<T>(KProcess process, int id)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
return dict.GetData<T>(id);
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
public object Delete(KProcess process, int id)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
return dict.Delete(id);
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-04 20:23:37 +00:00
|
|
|
public ICollection<object> DeleteProcess(KProcess process)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
if (_dictByProcess.TryRemove(process, out IdDictionary dict))
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-12-04 20:23:37 +00:00
|
|
|
return dict.Clear();
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|