Bug 1932613 - temporarily disable browser_ml_end_to_end.js for permanent failures...
[gecko.git] / xpcom / threads / nsThreadPool.h
blobe90c6063aab12d46532161bcef0c1711c0b1674d
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 nsThreadPool_h__
8 #define nsThreadPool_h__
10 #include "nsIThread.h"
11 #include "nsIThreadPool.h"
12 #include "nsIRunnable.h"
13 #include "nsCOMArray.h"
14 #include "nsCOMPtr.h"
15 #include "nsThreadUtils.h"
16 #include "mozilla/Atomics.h"
17 #include "mozilla/AlreadyAddRefed.h"
18 #include "mozilla/CondVar.h"
19 #include "mozilla/EventQueue.h"
20 #include "mozilla/LinkedList.h"
21 #include "mozilla/Mutex.h"
23 class nsIThread;
25 class nsThreadPool final : public mozilla::Runnable, public nsIThreadPool {
26 public:
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_NSIEVENTTARGET_FULL
29 NS_DECL_NSITHREADPOOL
30 NS_DECL_NSIRUNNABLE
32 nsThreadPool();
34 static void InitTLS();
35 static nsThreadPool* GetCurrentThreadPool();
37 private:
38 ~nsThreadPool();
40 struct MRUIdleEntry; // forward declaration only, see nsThreadPool.cpp
42 void ShutdownThread(nsIThread* aThread);
43 nsresult PutEvent(nsIRunnable* aEvent);
44 nsresult PutEvent(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags);
45 void NotifyChangeToAllIdleThreads() MOZ_REQUIRES(mMutex);
47 #ifdef DEBUG
48 void DebugLogPoolStatus(mozilla::MutexAutoLock& aProofOfLock,
49 MRUIdleEntry* aWakingEntry = nullptr)
50 MOZ_REQUIRES(mMutex);
51 #endif
53 mozilla::Mutex mMutex;
54 nsCOMArray<nsIThread> mThreads MOZ_GUARDED_BY(mMutex);
55 mozilla::EventQueue mEvents MOZ_GUARDED_BY(mMutex);
56 uint32_t mThreadLimit MOZ_GUARDED_BY(mMutex);
57 uint32_t mIdleThreadLimit MOZ_GUARDED_BY(mMutex);
58 mozilla::TimeDuration mIdleThreadGraceTimeout MOZ_GUARDED_BY(mMutex);
59 mozilla::TimeDuration mIdleThreadMaxTimeout MOZ_GUARDED_BY(mMutex);
60 mozilla::LinkedList<MRUIdleEntry> mMRUIdleThreads MOZ_GUARDED_BY(mMutex);
61 nsIThread::QoSPriority mQoSPriority MOZ_GUARDED_BY(mMutex);
62 uint32_t mStackSize MOZ_GUARDED_BY(mMutex);
63 nsCOMPtr<nsIThreadPoolListener> mListener MOZ_GUARDED_BY(mMutex);
64 mozilla::Atomic<bool, mozilla::Relaxed> mShutdown;
65 mozilla::Atomic<bool, mozilla::Relaxed> mIsAPoolThreadFree;
66 // set once before we start threads
67 nsCString mName MOZ_GUARDED_BY(mMutex);
68 nsThreadPoolNaming mThreadNaming; // all data inside this is atomic
71 #define NS_THREADPOOL_CID \
72 { /* 547ec2a8-315e-4ec4-888e-6e4264fe90eb */ \
73 0x547ec2a8, 0x315e, 0x4ec4, { \
74 0x88, 0x8e, 0x6e, 0x42, 0x64, 0xfe, 0x90, 0xeb \
75 } \
78 #endif // nsThreadPool_h__