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