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/. */
8 #include "mozilla/Monitor.h"
9 #include "nsThreadUtils.h"
10 #include "nsIObserver.h"
11 #include "nsProxyRelease.h"
16 // Wait for the event to run on the target thread without spinning the event
17 // loop on the calling thread. (Dispatching events to a thread using
18 // NS_DispatchAndSpinEventLoopUntilComplete would cause the event loop on the
19 // calling thread to spin.)
20 class SyncRunnableBase
: public Runnable
{
23 nsresult
DispatchToMainThreadAndWait();
27 virtual void RunOnTargetThread() = 0;
30 mozilla::Monitor monitor MOZ_UNANNOTATED
;
33 class NotifyObserverRunnable
: public Runnable
{
35 NotifyObserverRunnable(nsIObserver
* observer
, const char* topicStringLiteral
)
36 : Runnable("psm::NotifyObserverRunnable"),
37 mObserver(new nsMainThreadPtrHolder
<nsIObserver
>(
38 "psm::NotifyObserverRunnable::mObserver", observer
)),
39 mTopic(topicStringLiteral
) {}
42 nsMainThreadPtrHandle
<nsIObserver
> mObserver
;
43 const char* const mTopic
;
47 } // namespace mozilla