/src/mozilla-central/security/manager/ssl/PSMRunnable.h
Line | Count | Source (jump to first uncovered line) |
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 { namespace psm { |
14 | | |
15 | | // Wait for the event to run on the target thread without spinning the event |
16 | | // loop on the calling thread. (Dispatching events to a thread using |
17 | | // NS_DISPATCH_SYNC would cause the event loop on the calling thread to spin.) |
18 | | class SyncRunnableBase : public Runnable |
19 | | { |
20 | | public: |
21 | | NS_DECL_NSIRUNNABLE |
22 | | nsresult DispatchToMainThreadAndWait(); |
23 | | protected: |
24 | | SyncRunnableBase(); |
25 | | virtual void RunOnTargetThread() = 0; |
26 | | private: |
27 | | mozilla::Monitor monitor; |
28 | | }; |
29 | | |
30 | | class NotifyObserverRunnable : public Runnable |
31 | | { |
32 | | public: |
33 | | NotifyObserverRunnable(nsIObserver * observer, |
34 | | const char * topicStringLiteral) |
35 | | : Runnable("psm::NotifyObserverRunnable"), |
36 | | mObserver(new nsMainThreadPtrHolder<nsIObserver>( |
37 | | "psm::NotifyObserverRunnable::mObserver", observer)), |
38 | 0 | mTopic(topicStringLiteral) { |
39 | 0 | } |
40 | | NS_DECL_NSIRUNNABLE |
41 | | private: |
42 | | nsMainThreadPtrHandle<nsIObserver> mObserver; |
43 | | const char * const mTopic; |
44 | | }; |
45 | | |
46 | | } } // namespace mozilla::psm |
47 | | |
48 | | #endif |