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