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

--HG--
extra : source : ae110eaaa626064dd81188d4f587a2df1f439bd2
This commit is contained in:
Xidorn Quan 2015-09-29 09:28:22 +10:00
Родитель 661f0a0891
Коммит 5a61756f88
4 изменённых файлов: 51 добавлений и 44 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

@ -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_