Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / xpcom / threads / nsThreadPool.h
blobb10a2f5265841b54312323790cbd6d5554d6582e
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 "nsIThreadPool.h"
11 #include "nsIRunnable.h"
12 #include "nsCOMArray.h"
13 #include "nsCOMPtr.h"
14 #include "nsThreadUtils.h"
15 #include "mozilla/Atomics.h"
16 #include "mozilla/AlreadyAddRefed.h"
17 #include "mozilla/CondVar.h"
18 #include "mozilla/EventQueue.h"
19 #include "mozilla/Mutex.h"
21 class nsIThread;
23 class nsThreadPool final : public mozilla::Runnable, public nsIThreadPool {
24 public:
25 NS_DECL_ISUPPORTS_INHERITED
26 NS_DECL_NSIEVENTTARGET_FULL
27 NS_DECL_NSITHREADPOOL
28 NS_DECL_NSIRUNNABLE
30 nsThreadPool();
32 static void InitTLS();
33 static nsThreadPool* GetCurrentThreadPool();
35 private:
36 ~nsThreadPool();
38 void ShutdownThread(nsIThread* aThread);
39 nsresult PutEvent(nsIRunnable* aEvent);
40 nsresult PutEvent(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags);
42 mozilla::Mutex mMutex;
43 nsCOMArray<nsIThread> mThreads MOZ_GUARDED_BY(mMutex);
44 mozilla::CondVar mEventsAvailable MOZ_GUARDED_BY(mMutex);
45 mozilla::EventQueue mEvents MOZ_GUARDED_BY(mMutex);
46 uint32_t mThreadLimit MOZ_GUARDED_BY(mMutex);
47 uint32_t mIdleThreadLimit MOZ_GUARDED_BY(mMutex);
48 uint32_t mIdleThreadTimeout MOZ_GUARDED_BY(mMutex);
49 uint32_t mIdleCount MOZ_GUARDED_BY(mMutex);
50 nsIThread::QoSPriority mQoSPriority MOZ_GUARDED_BY(mMutex);
51 uint32_t mStackSize MOZ_GUARDED_BY(mMutex);
52 nsCOMPtr<nsIThreadPoolListener> mListener MOZ_GUARDED_BY(mMutex);
53 mozilla::Atomic<bool, mozilla::Relaxed> mShutdown;
54 bool mRegressiveMaxIdleTime MOZ_GUARDED_BY(mMutex);
55 mozilla::Atomic<bool, mozilla::Relaxed> mIsAPoolThreadFree;
56 // set once before we start threads
57 nsCString mName MOZ_GUARDED_BY(mMutex);
58 nsThreadPoolNaming mThreadNaming; // all data inside this is atomic
61 #define NS_THREADPOOL_CID \
62 { /* 547ec2a8-315e-4ec4-888e-6e4264fe90eb */ \
63 0x547ec2a8, 0x315e, 0x4ec4, { \
64 0x88, 0x8e, 0x6e, 0x42, 0x64, 0xfe, 0x90, 0xeb \
65 } \
68 #endif // nsThreadPool_h__