Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef _NSPSMBACKGROUNDTHREAD_H_ |
michael@0 | 6 | #define _NSPSMBACKGROUNDTHREAD_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "nspr.h" |
michael@0 | 9 | #include "nscore.h" |
michael@0 | 10 | #include "mozilla/CondVar.h" |
michael@0 | 11 | #include "mozilla/Mutex.h" |
michael@0 | 12 | #include "nsNSSComponent.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsPSMBackgroundThread |
michael@0 | 15 | { |
michael@0 | 16 | protected: |
michael@0 | 17 | static void nsThreadRunner(void *arg); |
michael@0 | 18 | virtual void Run(void) = 0; |
michael@0 | 19 | |
michael@0 | 20 | // used to join the thread |
michael@0 | 21 | PRThread *mThreadHandle; |
michael@0 | 22 | |
michael@0 | 23 | // Shared mutex used for condition variables, |
michael@0 | 24 | // and to protect access to mExitState. |
michael@0 | 25 | // Derived classes may use it to protect additional |
michael@0 | 26 | // resources. |
michael@0 | 27 | mozilla::Mutex mMutex; |
michael@0 | 28 | |
michael@0 | 29 | // Used to signal the thread's Run loop when a job is added |
michael@0 | 30 | // and/or exit is requested. |
michael@0 | 31 | mozilla::CondVar mCond; |
michael@0 | 32 | |
michael@0 | 33 | bool exitRequested(::mozilla::MutexAutoLock const & proofOfLock) const; |
michael@0 | 34 | bool exitRequestedNoLock() const { return mExitState != ePSMThreadRunning; } |
michael@0 | 35 | nsresult postStoppedEventToMainThread(::mozilla::MutexAutoLock const & proofOfLock); |
michael@0 | 36 | |
michael@0 | 37 | private: |
michael@0 | 38 | enum { |
michael@0 | 39 | ePSMThreadRunning = 0, |
michael@0 | 40 | ePSMThreadStopRequested = 1, |
michael@0 | 41 | ePSMThreadStopped = 2 |
michael@0 | 42 | } mExitState; |
michael@0 | 43 | |
michael@0 | 44 | // The thread's name. |
michael@0 | 45 | nsCString mName; |
michael@0 | 46 | |
michael@0 | 47 | public: |
michael@0 | 48 | nsPSMBackgroundThread(); |
michael@0 | 49 | virtual ~nsPSMBackgroundThread(); |
michael@0 | 50 | |
michael@0 | 51 | nsresult startThread(const nsCSubstring & name); |
michael@0 | 52 | void requestExit(); |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | |
michael@0 | 56 | #endif |