/src/mozilla-central/xpcom/threads/ThreadEventTarget.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_ThreadEventTarget_h |
8 | | #define mozilla_ThreadEventTarget_h |
9 | | |
10 | | #include "mozilla/MemoryReporting.h" |
11 | | #include "mozilla/Mutex.h" |
12 | | #include "mozilla/SynchronizedEventQueue.h" // for ThreadTargetSink |
13 | | #include "nsISerialEventTarget.h" |
14 | | |
15 | | namespace mozilla { |
16 | | |
17 | | // ThreadEventTarget handles the details of posting an event to a thread. It can |
18 | | // be used with any ThreadTargetSink implementation. |
19 | | class ThreadEventTarget final : public nsISerialEventTarget |
20 | | { |
21 | | public: |
22 | | ThreadEventTarget(ThreadTargetSink* aSink, |
23 | | bool aIsMainThread); |
24 | | |
25 | | NS_DECL_THREADSAFE_ISUPPORTS |
26 | | NS_DECL_NSIEVENTTARGET_FULL |
27 | | |
28 | | // Disconnects the target so that it can no longer post events. |
29 | 0 | void Disconnect(const MutexAutoLock& aProofOfLock) { mSink->Disconnect(aProofOfLock); } |
30 | | |
31 | | // Sets the thread for which IsOnCurrentThread returns true to the current thread. |
32 | | void SetCurrentThread(); |
33 | | |
34 | | size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const |
35 | 0 | { |
36 | 0 | size_t n = 0; |
37 | 0 | if (mSink) { |
38 | 0 | n += mSink->SizeOfIncludingThis(aMallocSizeOf); |
39 | 0 | } |
40 | 0 | return aMallocSizeOf(this) + n; |
41 | 0 | } |
42 | | |
43 | | private: |
44 | 0 | ~ThreadEventTarget() {} |
45 | | |
46 | | RefPtr<ThreadTargetSink> mSink; |
47 | | bool mIsMainThread; |
48 | | }; |
49 | | |
50 | | } // namespace mozilla |
51 | | |
52 | | #endif // mozilla_ThreadEventTarget_h |