Bug 1032573 part 4 - Add AnimationTimeline::ToTimelineTime helper method; r=dbaron
[gecko.git] / xpcom / threads / nsThreadManager.h
blob54d9c5d561f64d1c71ad70e6c740d0b8860d5fc7
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 nsThreadManager_h__
8 #define nsThreadManager_h__
10 #include "mozilla/Mutex.h"
11 #include "nsIThreadManager.h"
12 #include "nsRefPtrHashtable.h"
13 #include "nsThread.h"
15 class nsIRunnable;
17 class nsThreadManager : public nsIThreadManager
19 public:
20 NS_DECL_ISUPPORTS
21 NS_DECL_NSITHREADMANAGER
23 static nsThreadManager* get()
25 static nsThreadManager sInstance;
26 return &sInstance;
29 nsresult Init();
31 // Shutdown all threads. This function should only be called on the main
32 // thread of the application process.
33 void Shutdown();
35 // Called by nsThread to inform the ThreadManager it exists. This method
36 // must be called when the given thread is the current thread.
37 void RegisterCurrentThread(nsThread* aThread);
39 // Called by nsThread to inform the ThreadManager it is going away. This
40 // method must be called when the given thread is the current thread.
41 void UnregisterCurrentThread(nsThread* aThread);
43 // Returns the current thread. Returns null if OOM or if ThreadManager isn't
44 // initialized.
45 nsThread* GetCurrentThread();
47 // Returns the maximal number of threads that have been in existence
48 // simultaneously during the execution of the thread manager.
49 uint32_t GetHighestNumberOfThreads();
51 // This needs to be public in order to support static instantiation of this
52 // class with older compilers (e.g., egcs-2.91.66).
53 ~nsThreadManager()
57 private:
58 nsThreadManager()
59 : mCurThreadIndex(0)
60 , mMainPRThread(nullptr)
61 , mLock(nullptr)
62 , mInitialized(false)
63 , mCurrentNumberOfThreads(1)
64 , mHighestNumberOfThreads(1)
68 nsRefPtrHashtable<nsPtrHashKey<PRThread>, nsThread> mThreadsByPRThread;
69 unsigned mCurThreadIndex; // thread-local-storage index
70 nsRefPtr<nsThread> mMainThread;
71 PRThread* mMainPRThread;
72 // This is a pointer in order to allow creating nsThreadManager from
73 // the static context in debug builds.
74 nsAutoPtr<mozilla::Mutex> mLock; // protects tables
75 bool mInitialized;
77 // The current number of threads
78 uint32_t mCurrentNumberOfThreads;
79 // The highest number of threads encountered so far during the session
80 uint32_t mHighestNumberOfThreads;
83 #define NS_THREADMANAGER_CID \
84 { /* 7a4204c6-e45a-4c37-8ebb-6709a22c917c */ \
85 0x7a4204c6, \
86 0xe45a, \
87 0x4c37, \
88 {0x8e, 0xbb, 0x67, 0x09, 0xa2, 0x2c, 0x91, 0x7c} \
91 #endif // nsThreadManager_h__