|
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 nsRunnable |
|
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 nsRunnable |
|
31 { |
|
32 public: |
|
33 NotifyObserverRunnable(nsIObserver * observer, |
|
34 const char * topicStringLiteral) |
|
35 : mObserver(), mTopic(topicStringLiteral) { |
|
36 mObserver = new nsMainThreadPtrHolder<nsIObserver>(observer); |
|
37 } |
|
38 NS_DECL_NSIRUNNABLE |
|
39 private: |
|
40 nsMainThreadPtrHandle<nsIObserver> mObserver; |
|
41 const char * const mTopic; |
|
42 }; |
|
43 |
|
44 } } // namespace mozilla::psm |
|
45 |
|
46 #endif |