GlobalStateTable.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Ryujinx.HLE.HOS.Kernel;
  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. }