PSMRunnable.h (1413B)
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 #ifndef PSMRunnable_h 6 #define PSMRunnable_h 7 8 #include "mozilla/Monitor.h" 9 #include "nsThreadUtils.h" 10 #include "nsIObserver.h" 11 #include "nsProxyRelease.h" 12 13 namespace mozilla { 14 namespace psm { 15 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 { 21 public: 22 NS_DECL_NSIRUNNABLE 23 nsresult DispatchToMainThreadAndWait(); 24 25 protected: 26 SyncRunnableBase(); 27 virtual void RunOnTargetThread() = 0; 28 29 private: 30 mozilla::Monitor monitor MOZ_UNANNOTATED; 31 }; 32 33 class NotifyObserverRunnable : public Runnable { 34 public: 35 NotifyObserverRunnable(nsIObserver* observer, const char* topicStringLiteral) 36 : Runnable("psm::NotifyObserverRunnable"), 37 mObserver(new nsMainThreadPtrHolder<nsIObserver>( 38 "psm::NotifyObserverRunnable::mObserver", observer)), 39 mTopic(topicStringLiteral) {} 40 NS_DECL_NSIRUNNABLE 41 private: 42 nsMainThreadPtrHandle<nsIObserver> mObserver; 43 const char* const mTopic; 44 }; 45 46 } // namespace psm 47 } // namespace mozilla 48 49 #endif