Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef _NSPSMBACKGROUNDTHREAD_H_
6 #define _NSPSMBACKGROUNDTHREAD_H_
8 #include "nspr.h"
9 #include "nscore.h"
10 #include "mozilla/CondVar.h"
11 #include "mozilla/Mutex.h"
12 #include "nsNSSComponent.h"
14 class nsPSMBackgroundThread
15 {
16 protected:
17 static void nsThreadRunner(void *arg);
18 virtual void Run(void) = 0;
20 // used to join the thread
21 PRThread *mThreadHandle;
23 // Shared mutex used for condition variables,
24 // and to protect access to mExitState.
25 // Derived classes may use it to protect additional
26 // resources.
27 mozilla::Mutex mMutex;
29 // Used to signal the thread's Run loop when a job is added
30 // and/or exit is requested.
31 mozilla::CondVar mCond;
33 bool exitRequested(::mozilla::MutexAutoLock const & proofOfLock) const;
34 bool exitRequestedNoLock() const { return mExitState != ePSMThreadRunning; }
35 nsresult postStoppedEventToMainThread(::mozilla::MutexAutoLock const & proofOfLock);
37 private:
38 enum {
39 ePSMThreadRunning = 0,
40 ePSMThreadStopRequested = 1,
41 ePSMThreadStopped = 2
42 } mExitState;
44 // The thread's name.
45 nsCString mName;
47 public:
48 nsPSMBackgroundThread();
49 virtual ~nsPSMBackgroundThread();
51 nsresult startThread(const nsCSubstring & name);
52 void requestExit();
53 };
56 #endif