GlobalStateTable.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Ryujinx.HLE.HOS.Kernel.Process;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.HLE.HOS
  5. {
  6. class GlobalStateTable
  7. {
  8. private ConcurrentDictionary<KProcess, IdDictionary> _dictByProcess;
  9. public GlobalStateTable()
  10. {
  11. _dictByProcess = new ConcurrentDictionary<KProcess, IdDictionary>();
  12. }
  13. public bool Add(KProcess process, int id, object data)
  14. {
  15. IdDictionary dict = _dictByProcess.GetOrAdd(process, (key) => new IdDictionary());
  16. return dict.Add(id, data);
  17. }
  18. public int Add(KProcess process, object data)
  19. {
  20. IdDictionary dict = _dictByProcess.GetOrAdd(process, (key) => new IdDictionary());
  21. return dict.Add(data);
  22. }
  23. public object GetData(KProcess process, int id)
  24. {
  25. if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
  26. {
  27. return dict.GetData(id);
  28. }
  29. return null;
  30. }
  31. public T GetData<T>(KProcess process, int id)
  32. {
  33. if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
  34. {
  35. return dict.GetData<T>(id);
  36. }
  37. return default(T);
  38. }
  39. public object Delete(KProcess process, int id)
  40. {
  41. if (_dictByProcess.TryGetValue(process, out IdDictionary dict))
  42. {
  43. return dict.Delete(id);
  44. }
  45. return null;
  46. }
  47. public ICollection<object> DeleteProcess(KProcess process)
  48. {
  49. if (_dictByProcess.TryRemove(process, out IdDictionary dict))
  50. {
  51. return dict.Clear();
  52. }
  53. return null;
  54. }
  55. }
  56. }