security/manager/ssl/src/nsPSMBackgroundThread.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/ssl/src/nsPSMBackgroundThread.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef _NSPSMBACKGROUNDTHREAD_H_
     1.9 +#define _NSPSMBACKGROUNDTHREAD_H_
    1.10 +
    1.11 +#include "nspr.h"
    1.12 +#include "nscore.h"
    1.13 +#include "mozilla/CondVar.h"
    1.14 +#include "mozilla/Mutex.h"
    1.15 +#include "nsNSSComponent.h"
    1.16 +
    1.17 +class nsPSMBackgroundThread
    1.18 +{
    1.19 +protected:
    1.20 +  static void nsThreadRunner(void *arg);
    1.21 +  virtual void Run(void) = 0;
    1.22 +
    1.23 +  // used to join the thread
    1.24 +  PRThread *mThreadHandle;
    1.25 +
    1.26 +  // Shared mutex used for condition variables,
    1.27 +  // and to protect access to mExitState.
    1.28 +  // Derived classes may use it to protect additional
    1.29 +  // resources.
    1.30 +  mozilla::Mutex mMutex;
    1.31 +
    1.32 +  // Used to signal the thread's Run loop when a job is added 
    1.33 +  // and/or exit is requested.
    1.34 +  mozilla::CondVar mCond;
    1.35 +
    1.36 +  bool exitRequested(::mozilla::MutexAutoLock const & proofOfLock) const;
    1.37 +  bool exitRequestedNoLock() const { return mExitState != ePSMThreadRunning; }
    1.38 +  nsresult postStoppedEventToMainThread(::mozilla::MutexAutoLock const & proofOfLock);
    1.39 +
    1.40 +private:
    1.41 +  enum {
    1.42 +    ePSMThreadRunning = 0,
    1.43 +    ePSMThreadStopRequested = 1,
    1.44 +    ePSMThreadStopped = 2
    1.45 +  } mExitState;
    1.46 +
    1.47 +  // The thread's name.
    1.48 +  nsCString mName;
    1.49 +
    1.50 +public:
    1.51 +  nsPSMBackgroundThread();
    1.52 +  virtual ~nsPSMBackgroundThread();
    1.53 +
    1.54 +  nsresult startThread(const nsCSubstring & name);
    1.55 +  void requestExit();
    1.56 +};
    1.57 +
    1.58 +
    1.59 +#endif

mercurial