blob: faafb14c609402d21dc005db8156a587304e65d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef PSMRunnable_h
#define PSMRunnable_h
#include "mozilla/Monitor.h"
#include "nsThreadUtils.h"
#include "nsIObserver.h"
#include "nsProxyRelease.h"
namespace mozilla {
namespace psm {
// Wait for the event to run on the target thread without spinning the event
// loop on the calling thread. (Dispatching events to a thread using
// NS_DispatchAndSpinEventLoopUntilComplete would cause the event loop on the
// calling thread to spin.)
class SyncRunnableBase : public Runnable {
public:
NS_DECL_NSIRUNNABLE
nsresult DispatchToMainThreadAndWait();
protected:
SyncRunnableBase();
virtual void RunOnTargetThread() = 0;
private:
mozilla::Monitor monitor MOZ_UNANNOTATED;
};
class NotifyObserverRunnable : public Runnable {
public:
NotifyObserverRunnable(nsIObserver* observer, const char* topicStringLiteral)
: Runnable("psm::NotifyObserverRunnable"),
mObserver(new nsMainThreadPtrHolder<nsIObserver>(
"psm::NotifyObserverRunnable::mObserver", observer)),
mTopic(topicStringLiteral) {}
NS_DECL_NSIRUNNABLE
private:
nsMainThreadPtrHandle<nsIObserver> mObserver;
const char* const mTopic;
};
} // namespace psm
} // namespace mozilla
#endif
|