PSMRunnable.cpp 929 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "PSMRunnable.h"
  5. namespace mozilla { namespace psm {
  6. SyncRunnableBase::SyncRunnableBase()
  7. : monitor("SyncRunnableBase::monitor")
  8. {
  9. }
  10. nsresult
  11. SyncRunnableBase::DispatchToMainThreadAndWait()
  12. {
  13. nsresult rv;
  14. if (NS_IsMainThread()) {
  15. RunOnTargetThread();
  16. rv = NS_OK;
  17. } else {
  18. mozilla::MonitorAutoLock lock(monitor);
  19. rv = NS_DispatchToMainThread(this);
  20. if (NS_SUCCEEDED(rv)) {
  21. lock.Wait();
  22. }
  23. }
  24. return rv;
  25. }
  26. NS_IMETHODIMP
  27. SyncRunnableBase::Run()
  28. {
  29. RunOnTargetThread();
  30. mozilla::MonitorAutoLock(monitor).Notify();
  31. return NS_OK;
  32. }
  33. nsresult
  34. NotifyObserverRunnable::Run()
  35. {
  36. mObserver->Observe(nullptr, mTopic, nullptr);
  37. return NS_OK;
  38. }
  39. } } // namespace mozilla::psm