blob: b43bc62c6b4e88b83ee17df71a80a2aca829d0cb (
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
|
/* 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_DISPATCH_SYNC 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;
};
class NotifyObserverRunnable : public Runnable
{
public:
NotifyObserverRunnable(nsIObserver * observer,
const char * topicStringLiteral)
: mObserver(new nsMainThreadPtrHolder<nsIObserver>(observer)),
mTopic(topicStringLiteral) {
}
NS_DECL_NSIRUNNABLE
private:
nsMainThreadPtrHandle<nsIObserver> mObserver;
const char * const mTopic;
};
} } // namespace mozilla::psm
#endif
|