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"
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
{
22 ThreadEventTarget(ThreadTargetSink
* aSink
, bool aIsMainThread
,
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
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 {
42 n
+= mSink
->SizeOfIncludingThis(aMallocSizeOf
);
44 return aMallocSizeOf(this) + n
;
48 static void XPCOMShutdownThreadsNotificationFinished();
54 RefPtr
<ThreadTargetSink
> mSink
;
56 const bool mIsMainThread
;
58 const bool mBlockDispatch
;
61 } // namespace mozilla
63 #endif // mozilla_ThreadEventTarget_h