Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / xpcom / threads / ThreadEventTarget.h
blobb78411aa8056f3f549dc6d7b731819ef1696020c
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/. */
7 #ifndef mozilla_ThreadEventTarget_h
8 #define mozilla_ThreadEventTarget_h
10 #include "mozilla/MemoryReporting.h"
11 #include "mozilla/Mutex.h"
12 #include "mozilla/SynchronizedEventQueue.h" // for ThreadTargetSink
13 #include "nsISerialEventTarget.h"
15 namespace mozilla {
16 class DelayedRunnable;
18 // ThreadEventTarget handles the details of posting an event to a thread. It can
19 // be used with any ThreadTargetSink implementation.
20 class ThreadEventTarget final : public nsISerialEventTarget {
21 public:
22 ThreadEventTarget(ThreadTargetSink* aSink, bool aIsMainThread,
23 bool aBlockDispatch);
25 NS_DECL_THREADSAFE_ISUPPORTS
26 NS_DECL_NSIEVENTTARGET_FULL
28 // Disconnects the target so that it can no longer post events.
29 void Disconnect(const MutexAutoLock& aProofOfLock) {
30 mSink->Disconnect(aProofOfLock);
33 // Sets the thread for which IsOnCurrentThread returns true to the current
34 // thread.
35 void SetCurrentThread(PRThread* aThread);
36 // Call ClearCurrentThread() before the PRThread is deleted on thread join.
37 void ClearCurrentThread();
39 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
40 size_t n = 0;
41 if (mSink) {
42 n += mSink->SizeOfIncludingThis(aMallocSizeOf);
44 return aMallocSizeOf(this) + n;
47 #ifdef DEBUG
48 static void XPCOMShutdownThreadsNotificationFinished();
49 #endif
51 private:
52 ~ThreadEventTarget();
54 RefPtr<ThreadTargetSink> mSink;
55 #ifdef DEBUG
56 const bool mIsMainThread;
57 #endif
58 const bool mBlockDispatch;
61 } // namespace mozilla
63 #endif // mozilla_ThreadEventTarget_h