bug 1301157 - remove nsPSMBackgroundThread (dead code) r?jcj draft
authorDavid Keeler <dkeeler@mozilla.com>
Wed, 07 Sep 2016 12:43:27 -0700
changeset 411254 4cb81812789e2df5f2372a3912deea6fb77bb75d
parent 410335 394f02edb7cb33ad70074c77b523451749c5ed0b
child 530694 9992f4c88b232698b80015cdda140d4927e4d669
push id28858
push userdkeeler@mozilla.com
push dateWed, 07 Sep 2016 19:45:07 +0000
reviewersjcj
bugs1301157, 1284946
milestone51.0a1
bug 1301157 - remove nsPSMBackgroundThread (dead code) r?jcj As of bug 1284946, nothing uses nsPSMBackgroundThread, so it's just dead code that is removed by this patch. MozReview-Commit-ID: 24HWFHIeCX9
security/manager/ssl/moz.build
security/manager/ssl/nsPSMBackgroundThread.cpp
security/manager/ssl/nsPSMBackgroundThread.h
--- a/security/manager/ssl/moz.build
+++ b/security/manager/ssl/moz.build
@@ -117,17 +117,16 @@ UNIFIED_SOURCES += [
     'nsNSSShutDown.cpp',
     'nsNSSU2FToken.cpp',
     'nsNSSVersion.cpp',
     'nsNTLMAuthModule.cpp',
     'nsPK11TokenDB.cpp',
     'nsPKCS11Slot.cpp',
     'nsPKCS12Blob.cpp',
     'nsProtectedAuthThread.cpp',
-    'nsPSMBackgroundThread.cpp',
     'nsRandomGenerator.cpp',
     'nsSecureBrowserUIImpl.cpp',
     'nsSecurityHeaderParser.cpp',
     'NSSErrorsService.cpp',
     'nsSiteSecurityService.cpp',
     'nsSSLSocketProvider.cpp',
     'nsSSLStatus.cpp',
     'nsTLSSocketProvider.cpp',
deleted file mode 100644
--- a/security/manager/ssl/nsPSMBackgroundThread.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsPSMBackgroundThread.h"
-#include "nsThreadUtils.h"
-
-using namespace mozilla;
-
-void nsPSMBackgroundThread::nsThreadRunner(void *arg)
-{
-  nsPSMBackgroundThread *self = static_cast<nsPSMBackgroundThread *>(arg);
-  PR_SetCurrentThreadName(self->mName.BeginReading());
-  self->Run();
-}
-
-nsPSMBackgroundThread::nsPSMBackgroundThread()
-: mThreadHandle(nullptr),
-  mMutex("nsPSMBackgroundThread.mMutex"),
-  mCond(mMutex, "nsPSMBackgroundThread.mCond"),
-  mExitState(ePSMThreadRunning)
-{
-}
-
-nsresult nsPSMBackgroundThread::startThread(const nsCSubstring & name)
-{
-  mName = name;
-
-  mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsThreadRunner, static_cast<void*>(this), 
-    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
-
-  NS_ASSERTION(mThreadHandle, "Could not create nsPSMBackgroundThread\n");
-  
-  if (!mThreadHandle)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  return NS_OK;
-}
-
-nsPSMBackgroundThread::~nsPSMBackgroundThread()
-{
-}
-
-bool
-nsPSMBackgroundThread::exitRequested(const MutexAutoLock & /*proofOfLock*/) const
-{
-  return exitRequestedNoLock();
-}
-
-nsresult
-nsPSMBackgroundThread::postStoppedEventToMainThread(
-    MutexAutoLock const & /*proofOfLock*/)
-{
-  NS_ASSERTION(PR_GetCurrentThread() == mThreadHandle,
-               "Background thread stopped from another thread");
-
-  mExitState = ePSMThreadStopped;
-  // requestExit is waiting for an event, so give it one.
-  return NS_DispatchToMainThread(new Runnable());
-}
-
-void nsPSMBackgroundThread::requestExit()
-{
-  NS_ASSERTION(NS_IsMainThread(),
-               "nsPSMBackgroundThread::requestExit called off main thread.");
-
-  if (!mThreadHandle)
-    return;
-
-  {
-    MutexAutoLock threadLock(mMutex);
-    if (mExitState < ePSMThreadStopRequested) {
-      mExitState = ePSMThreadStopRequested;
-      mCond.NotifyAll();
-    }
-  }
-  
-  nsCOMPtr<nsIThread> mainThread = do_GetCurrentThread();
-  for (;;) {
-    {
-      MutexAutoLock threadLock(mMutex);
-      if (mExitState == ePSMThreadStopped)
-        break;
-    }
-    NS_ProcessPendingEvents(mainThread, PR_MillisecondsToInterval(50));
-  }
-
-  PR_JoinThread(mThreadHandle);
-  mThreadHandle = nullptr;
-}
deleted file mode 100644
--- a/security/manager/ssl/nsPSMBackgroundThread.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _NSPSMBACKGROUNDTHREAD_H_
-#define _NSPSMBACKGROUNDTHREAD_H_
-
-#include "nspr.h"
-#include "nscore.h"
-#include "mozilla/CondVar.h"
-#include "mozilla/Mutex.h"
-#include "nsNSSComponent.h"
-
-class nsPSMBackgroundThread
-{
-protected:
-  static void nsThreadRunner(void *arg);
-  virtual void Run(void) = 0;
-
-  // used to join the thread
-  PRThread *mThreadHandle;
-
-  // Shared mutex used for condition variables,
-  // and to protect access to mExitState.
-  // Derived classes may use it to protect additional
-  // resources.
-  mozilla::Mutex mMutex;
-
-  // Used to signal the thread's Run loop when a job is added 
-  // and/or exit is requested.
-  mozilla::CondVar mCond;
-
-  bool exitRequested(::mozilla::MutexAutoLock const & proofOfLock) const;
-  bool exitRequestedNoLock() const { return mExitState != ePSMThreadRunning; }
-  nsresult postStoppedEventToMainThread(::mozilla::MutexAutoLock const & proofOfLock);
-
-private:
-  enum {
-    ePSMThreadRunning = 0,
-    ePSMThreadStopRequested = 1,
-    ePSMThreadStopped = 2
-  } mExitState;
-
-  // The thread's name.
-  nsCString mName;
-
-public:
-  nsPSMBackgroundThread();
-  virtual ~nsPSMBackgroundThread();
-
-  nsresult startThread(const nsCSubstring & name);
-  void requestExit();
-};
-
-
-#endif