GlobalStateTable.cs 1.7 KB

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