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