SmRegistry.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Ryujinx.HLE.HOS.Kernel.Ipc;
  2. using System.Collections.Concurrent;
  3. using System.Threading;
  4. namespace Ryujinx.HLE.HOS.Services.Sm
  5. {
  6. class SmRegistry
  7. {
  8. private readonly ConcurrentDictionary<string, KPort> _registeredServices;
  9. private readonly AutoResetEvent _serviceRegistrationEvent;
  10. public SmRegistry()
  11. {
  12. _registeredServices = new ConcurrentDictionary<string, KPort>();
  13. _serviceRegistrationEvent = new AutoResetEvent(false);
  14. }
  15. public bool TryGetService(string name, out KPort port)
  16. {
  17. return _registeredServices.TryGetValue(name, out port);
  18. }
  19. public bool TryRegister(string name, KPort port)
  20. {
  21. if (_registeredServices.TryAdd(name, port))
  22. {
  23. _serviceRegistrationEvent.Set();
  24. return true;
  25. }
  26. return false;
  27. }
  28. public bool Unregister(string name)
  29. {
  30. return _registeredServices.TryRemove(name, out _);
  31. }
  32. public bool IsServiceRegistered(string name)
  33. {
  34. return _registeredServices.TryGetValue(name, out _);
  35. }
  36. public void WaitForServiceRegistration()
  37. {
  38. _serviceRegistrationEvent.WaitOne();
  39. }
  40. }
  41. }