Bug 1186745 part 2 - Move nsThreadSyncDispatch class to its own header file. r=froydnj

This commit is contained in:
Xidorn Quan 2015-10-06 13:00:59 +11:00
parent ca2ef41c62
commit 067f7da82a
4 changed files with 51 additions and 44 deletions

View File

@ -36,6 +36,7 @@
#include "nsXPCOMPrivate.h"
#include "mozilla/ChaosMode.h"
#include "mozilla/TimeStamp.h"
#include "nsThreadSyncDispatch.h"
#include "LeakRefPtr.h"
#ifdef MOZ_CRASHREPORTER
@ -1172,20 +1173,6 @@ nsThread::SetScriptObserver(mozilla::CycleCollectedJSRuntime* aScriptObserver)
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsThreadSyncDispatch::Run()
{
if (mSyncTask) {
mResult = mSyncTask->Run();
mSyncTask = nullptr;
// unblock the origin thread
mOrigin->Dispatch(this, NS_DISPATCH_NORMAL);
}
return NS_OK;
}
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS(nsThread::nsNestedEventTarget, nsIEventTarget)
NS_IMETHODIMP

View File

@ -207,36 +207,6 @@ protected:
MainThreadFlag mIsMainThread;
};
//-----------------------------------------------------------------------------
class nsThreadSyncDispatch : public nsRunnable
{
public:
nsThreadSyncDispatch(nsIThread* aOrigin, already_AddRefed<nsIRunnable>&& aTask)
: mOrigin(aOrigin)
, mSyncTask(aTask)
, mResult(NS_ERROR_NOT_INITIALIZED)
{
}
bool IsPending()
{
return mSyncTask != nullptr;
}
nsresult Result()
{
return mResult;
}
private:
NS_DECL_NSIRUNNABLE
nsCOMPtr<nsIThread> mOrigin;
nsCOMPtr<nsIRunnable> mSyncTask;
nsresult mResult;
};
#if defined(XP_UNIX) && !defined(ANDROID) && !defined(DEBUG) && HAVE_UALARM \
&& defined(_GNU_SOURCE)
# define MOZ_CANARY

View File

@ -12,6 +12,7 @@
#include "nsAutoPtr.h"
#include "prinrval.h"
#include "mozilla/Logging.h"
#include "nsThreadSyncDispatch.h"
using namespace mozilla;

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 nsThreadSyncDispatch_h_
#define nsThreadSyncDispatch_h_
#include "nsThreadUtils.h"
class nsThreadSyncDispatch : public nsRunnable
{
public:
nsThreadSyncDispatch(nsIThread* aOrigin, already_AddRefed<nsIRunnable>&& aTask)
: mOrigin(aOrigin)
, mSyncTask(aTask)
, mResult(NS_ERROR_NOT_INITIALIZED)
{
}
bool IsPending()
{
return mSyncTask != nullptr;
}
nsresult Result()
{
return mResult;
}
private:
NS_IMETHOD Run() override
{
if (mSyncTask) {
mResult = mSyncTask->Run();
mSyncTask = nullptr;
// unblock the origin thread
mOrigin->Dispatch(this, NS_DISPATCH_NORMAL);
}
return NS_OK;
}
nsCOMPtr<nsIThread> mOrigin;
nsCOMPtr<nsIRunnable> mSyncTask;
nsresult mResult;
};
#endif // nsThreadSyncDispatch_h_