michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef PSMRunnable_h michael@0: #define PSMRunnable_h michael@0: michael@0: #include "mozilla/Monitor.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsProxyRelease.h" michael@0: michael@0: namespace mozilla { namespace psm { michael@0: michael@0: // Wait for the event to run on the target thread without spinning the event michael@0: // loop on the calling thread. (Dispatching events to a thread using michael@0: // NS_DISPATCH_SYNC would cause the event loop on the calling thread to spin.) michael@0: class SyncRunnableBase : public nsRunnable michael@0: { michael@0: public: michael@0: NS_DECL_NSIRUNNABLE michael@0: nsresult DispatchToMainThreadAndWait(); michael@0: protected: michael@0: SyncRunnableBase(); michael@0: virtual void RunOnTargetThread() = 0; michael@0: private: michael@0: mozilla::Monitor monitor; michael@0: }; michael@0: michael@0: class NotifyObserverRunnable : public nsRunnable michael@0: { michael@0: public: michael@0: NotifyObserverRunnable(nsIObserver * observer, michael@0: const char * topicStringLiteral) michael@0: : mObserver(), mTopic(topicStringLiteral) { michael@0: mObserver = new nsMainThreadPtrHolder(observer); michael@0: } michael@0: NS_DECL_NSIRUNNABLE michael@0: private: michael@0: nsMainThreadPtrHandle mObserver; michael@0: const char * const mTopic; michael@0: }; michael@0: michael@0: } } // namespace mozilla::psm michael@0: michael@0: #endif