ServiceTable.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Ryujinx.Horizon.LogManager;
  2. using Ryujinx.Horizon.Prepo;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. namespace Ryujinx.Horizon
  6. {
  7. public class ServiceTable
  8. {
  9. private int _readyServices;
  10. private int _totalServices;
  11. private readonly ManualResetEvent _servicesReadyEvent = new(false);
  12. public IEnumerable<ServiceEntry> GetServices(HorizonOptions options)
  13. {
  14. List<ServiceEntry> entries = new();
  15. void RegisterService<T>() where T : IService
  16. {
  17. entries.Add(new ServiceEntry(T.Main, this, options));
  18. }
  19. RegisterService<LmMain>();
  20. RegisterService<PrepoMain>();
  21. _totalServices = entries.Count;
  22. return entries;
  23. }
  24. internal void SignalServiceReady()
  25. {
  26. if (Interlocked.Increment(ref _readyServices) == _totalServices)
  27. {
  28. _servicesReadyEvent.Set();
  29. }
  30. }
  31. public void WaitServicesReady()
  32. {
  33. _servicesReadyEvent.WaitOne();
  34. }
  35. protected virtual void Dispose(bool disposing)
  36. {
  37. if (disposing)
  38. {
  39. _servicesReadyEvent.Dispose();
  40. }
  41. }
  42. public void Dispose()
  43. {
  44. Dispose(true);
  45. }
  46. }
  47. }