PSMRunnable.cpp (979B)
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 5 #include "PSMRunnable.h" 6 7 namespace mozilla { 8 namespace psm { 9 10 SyncRunnableBase::SyncRunnableBase() 11 : Runnable("psm::SyncRunnableBase"), monitor("SyncRunnableBase::monitor") {} 12 13 nsresult SyncRunnableBase::DispatchToMainThreadAndWait() { 14 nsresult rv; 15 if (NS_IsMainThread()) { 16 RunOnTargetThread(); 17 rv = NS_OK; 18 } else { 19 mozilla::MonitorAutoLock lock(monitor); 20 rv = NS_DispatchToMainThread(this); 21 if (NS_SUCCEEDED(rv)) { 22 lock.Wait(); 23 } 24 } 25 26 return rv; 27 } 28 29 NS_IMETHODIMP 30 SyncRunnableBase::Run() { 31 RunOnTargetThread(); 32 mozilla::MonitorAutoLock(monitor).Notify(); 33 return NS_OK; 34 } 35 36 nsresult NotifyObserverRunnable::Run() { 37 mObserver->Observe(nullptr, mTopic, nullptr); 38 return NS_OK; 39 } 40 41 } // namespace psm 42 } // namespace mozilla