security/manager/ssl/PSMRunnable.cpp
author Sylvestre Ledru <sledru@mozilla.com>
Thu, 06 Jul 2017 14:00:35 +0200
changeset 418830 6a629adbb62a299d7208373d1c6f375149d2afdb
parent 417235 312f7a5a2c08d394a2403c837e5ee546dd4103d7
child 508163 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Bug 1378712 - Remove all trailing whitespaces r=Ehsan MozReview-Commit-ID: Kdz2xtTF9EG

/* 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 "PSMRunnable.h"

namespace mozilla { namespace psm {

SyncRunnableBase::SyncRunnableBase()
  : Runnable("psm::SyncRunnableBase")
  , monitor("SyncRunnableBase::monitor")
{
}

nsresult
SyncRunnableBase::DispatchToMainThreadAndWait()
{
  nsresult rv;
  if (NS_IsMainThread()) {
    RunOnTargetThread();
    rv = NS_OK;
  } else {
    mozilla::MonitorAutoLock lock(monitor);
    rv = NS_DispatchToMainThread(this);
    if (NS_SUCCEEDED(rv)) {
      lock.Wait();
    }
  }

  return rv;
}

NS_IMETHODIMP
SyncRunnableBase::Run()
{
  RunOnTargetThread();
  mozilla::MonitorAutoLock(monitor).Notify();
  return NS_OK;
}

nsresult
NotifyObserverRunnable::Run()
{
  mObserver->Observe(nullptr, mTopic, nullptr);
  return NS_OK;
}

} } // namespace mozilla::psm