1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/PSMRunnable.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 +* License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef PSMRunnable_h 1.9 +#define PSMRunnable_h 1.10 + 1.11 +#include "mozilla/Monitor.h" 1.12 +#include "nsThreadUtils.h" 1.13 +#include "nsIObserver.h" 1.14 +#include "nsProxyRelease.h" 1.15 + 1.16 +namespace mozilla { namespace psm { 1.17 + 1.18 +// Wait for the event to run on the target thread without spinning the event 1.19 +// loop on the calling thread. (Dispatching events to a thread using 1.20 +// NS_DISPATCH_SYNC would cause the event loop on the calling thread to spin.) 1.21 +class SyncRunnableBase : public nsRunnable 1.22 +{ 1.23 +public: 1.24 + NS_DECL_NSIRUNNABLE 1.25 + nsresult DispatchToMainThreadAndWait(); 1.26 +protected: 1.27 + SyncRunnableBase(); 1.28 + virtual void RunOnTargetThread() = 0; 1.29 +private: 1.30 + mozilla::Monitor monitor; 1.31 +}; 1.32 + 1.33 +class NotifyObserverRunnable : public nsRunnable 1.34 +{ 1.35 +public: 1.36 + NotifyObserverRunnable(nsIObserver * observer, 1.37 + const char * topicStringLiteral) 1.38 + : mObserver(), mTopic(topicStringLiteral) { 1.39 + mObserver = new nsMainThreadPtrHolder<nsIObserver>(observer); 1.40 + } 1.41 + NS_DECL_NSIRUNNABLE 1.42 +private: 1.43 + nsMainThreadPtrHandle<nsIObserver> mObserver; 1.44 + const char * const mTopic; 1.45 +}; 1.46 + 1.47 +} } // namespace mozilla::psm 1.48 + 1.49 +#endif