зеркало из https://github.com/mozilla/gecko-dev.git
Back out 6 changesets (bug 1186745) for cpptest failure in runnable_utils_unittest, nrappkit_unittest, test_nr_socket_unittest
Backed out changeset c6142b815de0 (bug 1186745) Backed out changeset d8f740ef2430 (bug 1186745) Backed out changeset edc0b56d81fa (bug 1186745) Backed out changeset 383f8ac033ea (bug 1186745) Backed out changeset ce960a661987 (bug 1186745) Backed out changeset 3e9783023fb2 (bug 1186745) --HG-- extra : rebase_source : 4681d6abaaa927ddb863f944efc87e6c6f6c2e26
This commit is contained in:
Родитель
84f181826e
Коммит
c096566a7e
|
@ -75,8 +75,7 @@ const PRTime GetStartTime();
|
|||
|
||||
Task* CreateTracedTask(Task* aTask);
|
||||
|
||||
already_AddRefed<nsIRunnable>
|
||||
CreateTracedRunnable(already_AddRefed<nsIRunnable>&& aRunnable);
|
||||
already_AddRefed<nsIRunnable> CreateTracedRunnable(nsIRunnable* aRunnable);
|
||||
|
||||
// Free the TraceInfo allocated on a thread's TLS. Currently we are wrapping
|
||||
// tasks running on nsThreads and base::thread, so FreeTraceInfo is called at
|
||||
|
|
|
@ -90,9 +90,9 @@ TracedTaskCommon::ClearTLSTraceInfo()
|
|||
/**
|
||||
* Implementation of class TracedRunnable.
|
||||
*/
|
||||
TracedRunnable::TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj)
|
||||
TracedRunnable::TracedRunnable(nsIRunnable* aOriginalObj)
|
||||
: TracedTaskCommon()
|
||||
, mOriginalObj(Move(aOriginalObj))
|
||||
, mOriginalObj(aOriginalObj)
|
||||
{
|
||||
Init();
|
||||
LogVirtualTablePtr(mTaskId, mSourceEventId, *(int**)(aOriginalObj));
|
||||
|
@ -148,9 +148,9 @@ TracedTask::Run()
|
|||
* nsIRunnable object, aRunnable.
|
||||
*/
|
||||
already_AddRefed<nsIRunnable>
|
||||
CreateTracedRunnable(already_AddRefed<nsIRunnable>&& aRunnable)
|
||||
CreateTracedRunnable(nsIRunnable* aRunnable)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> runnable = new TracedRunnable(Move(aRunnable));
|
||||
nsCOMPtr<nsIRunnable> runnable = new TracedRunnable(aRunnable);
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class TracedRunnable : public TracedTaskCommon
|
|||
public:
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj);
|
||||
TracedRunnable(nsIRunnable* aOriginalObj);
|
||||
|
||||
private:
|
||||
virtual ~TracedRunnable();
|
||||
|
|
|
@ -106,7 +106,6 @@ if CONFIG['_MSC_VER']:
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
'../build',
|
||||
'../threads',
|
||||
]
|
||||
|
||||
if CONFIG['ENABLE_TESTS']:
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "LeakRefPtr.h"
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
# include "nsThreadManager.h"
|
||||
|
@ -28,8 +27,6 @@ using mozilla::IsVistaOrLater;
|
|||
#include <pratom.h>
|
||||
#include <prthread.h>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
#ifndef XPCOM_GLUE_AVOID_NSPR
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsRunnable, nsIRunnable)
|
||||
|
@ -142,11 +139,13 @@ NS_IsMainThread()
|
|||
}
|
||||
#endif
|
||||
|
||||
// It is common to call NS_DispatchToCurrentThread with a newly
|
||||
// allocated runnable with a refcount of zero. To keep us from leaking
|
||||
// the runnable if the dispatch method fails, we take a death grip.
|
||||
NS_METHOD
|
||||
NS_DispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent)
|
||||
NS_DispatchToCurrentThread(nsIRunnable* aEvent)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIRunnable> event(aEvent);
|
||||
nsCOMPtr<nsIRunnable> deathGrip = aEvent;
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
nsIThread* thread = NS_GetCurrentThread();
|
||||
if (!thread) {
|
||||
|
@ -154,47 +153,28 @@ NS_DispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent)
|
|||
}
|
||||
#else
|
||||
nsCOMPtr<nsIThread> thread;
|
||||
rv = NS_GetCurrentThread(getter_AddRefs(thread));
|
||||
nsresult rv = NS_GetCurrentThread(getter_AddRefs(thread));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
// To keep us from leaking the runnable if dispatch method fails,
|
||||
// we grab the reference on failures and release it.
|
||||
nsIRunnable* temp = event.get();
|
||||
rv = thread->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
// Dispatch() leaked the reference to the event, but due to caller's
|
||||
// assumptions, we shouldn't leak here. And given we are on the same
|
||||
// thread as the dispatch target, it's mostly safe to do it here.
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// It is common to call NS_DispatchToCurrentThread with a newly
|
||||
// allocated runnable with a refcount of zero. To keep us from leaking
|
||||
// the runnable if the dispatch method fails, we take a death grip.
|
||||
NS_METHOD
|
||||
NS_DispatchToCurrentThread(nsIRunnable* aEvent)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> event(aEvent);
|
||||
return NS_DispatchToCurrentThread(event.forget());
|
||||
return thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
NS_DispatchToMainThread(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aDispatchFlags)
|
||||
{
|
||||
LeakRefPtr<nsIRunnable> event(Move(aEvent));
|
||||
nsCOMPtr<nsIRunnable> event(aEvent);
|
||||
nsCOMPtr<nsIThread> thread;
|
||||
nsresult rv = NS_GetMainThread(getter_AddRefs(thread));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
NS_ASSERTION(false, "Failed NS_DispatchToMainThread() in shutdown; leaking");
|
||||
// NOTE: if you stop leaking here, adjust Promise::MaybeReportRejected(),
|
||||
// which assumes a leak here, or split into leaks and no-leaks versions
|
||||
return rv;
|
||||
nsIRunnable* temp = event.forget().take(); // leak without using "unused <<" due to Windows (boo)
|
||||
return temp ? rv : rv; // to make compiler not bletch on us
|
||||
}
|
||||
return thread->Dispatch(event.take(), aDispatchFlags);
|
||||
return thread->Dispatch(event.forget(), aDispatchFlags);
|
||||
}
|
||||
|
||||
// In the case of failure with a newly allocated runnable with a
|
||||
|
|
|
@ -106,8 +106,6 @@ extern NS_METHOD NS_GetCurrentThread(nsIThread** aResult);
|
|||
* If event is null.
|
||||
*/
|
||||
extern NS_METHOD NS_DispatchToCurrentThread(nsIRunnable* aEvent);
|
||||
extern NS_METHOD
|
||||
NS_DispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent);
|
||||
|
||||
/**
|
||||
* Dispatch the given event to the main thread.
|
||||
|
|
|
@ -38,7 +38,6 @@ DEFINES['XPCOM_GLUE'] = True
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
'../../build',
|
||||
'../../threads',
|
||||
]
|
||||
|
||||
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
|
||||
|
|
|
@ -30,7 +30,6 @@ DEFINES['XPCOM_GLUE'] = True
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
'../../../build',
|
||||
'../../../threads',
|
||||
]
|
||||
|
||||
# Statically link to the CRT on Windows
|
||||
|
|
|
@ -28,7 +28,6 @@ if CONFIG['_MSC_VER']:
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
'../../build',
|
||||
'../../threads',
|
||||
]
|
||||
|
||||
# Statically link to the CRT on Windows
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
/* Smart pointer which leaks its owning refcounted object by default. */
|
||||
|
||||
#ifndef LeakRefPtr_h
|
||||
#define LeakRefPtr_h
|
||||
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* Instance of this class behaves like a raw pointer which leaks the
|
||||
* resource its owning if not explicitly released.
|
||||
*/
|
||||
template<class T>
|
||||
class LeakRefPtr
|
||||
{
|
||||
public:
|
||||
explicit LeakRefPtr(already_AddRefed<T>&& aPtr)
|
||||
: mRawPtr(aPtr.take()) { }
|
||||
|
||||
explicit operator bool() const { return !!mRawPtr; }
|
||||
|
||||
LeakRefPtr<T>& operator=(already_AddRefed<T>&& aPtr)
|
||||
{
|
||||
mRawPtr = aPtr.take();
|
||||
return *this;
|
||||
}
|
||||
|
||||
already_AddRefed<T> take()
|
||||
{
|
||||
T* rawPtr = mRawPtr;
|
||||
mRawPtr = nullptr;
|
||||
return already_AddRefed<T>(rawPtr);
|
||||
}
|
||||
|
||||
private:
|
||||
T* mRawPtr;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // LeakRefPtr_h
|
|
@ -60,10 +60,7 @@ interface nsIEventTarget : nsISupports
|
|||
* any thread, and it may be called re-entrantly.
|
||||
*
|
||||
* @param event
|
||||
* The alreadyAddRefed<> event to dispatch.
|
||||
* NOTE that the event will be leaked if it fails to dispatch. Also note
|
||||
* that if "flags" includes DISPATCH_SYNC, it may return error from Run()
|
||||
* after a successful dispatch. In that case, the event is not leaked.
|
||||
* The alreadyAddRefed<> event to dispatch
|
||||
* @param flags
|
||||
* The flags modifying event dispatch. The flags are described in detail
|
||||
* below.
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
#include "nsXPCOMPrivate.h"
|
||||
#include "mozilla/ChaosMode.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "nsThreadSyncDispatch.h"
|
||||
#include "LeakRefPtr.h"
|
||||
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
@ -543,9 +541,6 @@ nsThread::PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget)
|
|||
nsresult
|
||||
nsThread::PutEvent(already_AddRefed<nsIRunnable>&& aEvent, nsNestedEventTarget* aTarget)
|
||||
{
|
||||
// We want to leak the reference when we fail to dispatch it, so that
|
||||
// we won't release the event in a wrong thread.
|
||||
LeakRefPtr<nsIRunnable> event(Move(aEvent));
|
||||
nsCOMPtr<nsIThreadObserver> obs;
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
|
@ -559,9 +554,11 @@ nsThread::PutEvent(already_AddRefed<nsIRunnable>&& aEvent, nsNestedEventTarget*
|
|||
nsChainedEventQueue* queue = aTarget ? aTarget->mQueue : &mEventsRoot;
|
||||
if (!queue || (queue == &mEventsRoot && mEventsAreDoomed)) {
|
||||
NS_WARNING("An event was posted to a thread that will never run it (rejected)");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIRunnable> temp(aEvent);
|
||||
nsIRunnable* temp2 = temp.forget().take(); // can't use unused << aEvent here due to Windows (boo)
|
||||
return temp2 ? NS_ERROR_UNEXPECTED : NS_ERROR_UNEXPECTED; // to make compiler not bletch on us
|
||||
}
|
||||
queue->PutEvent(event.take(), lock);
|
||||
queue->PutEvent(Move(aEvent), lock);
|
||||
|
||||
// Make sure to grab the observer before dropping the lock, otherwise the
|
||||
// event that we just placed into the queue could run and eventually delete
|
||||
|
@ -581,9 +578,7 @@ nsresult
|
|||
nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFlags,
|
||||
nsNestedEventTarget* aTarget)
|
||||
{
|
||||
// We want to leak the reference when we fail to dispatch it, so that
|
||||
// we won't release the event in a wrong thread.
|
||||
LeakRefPtr<nsIRunnable> event(Move(aEvent));
|
||||
nsCOMPtr<nsIRunnable> event(aEvent);
|
||||
if (NS_WARN_IF(!event)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
@ -594,9 +589,8 @@ nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFla
|
|||
}
|
||||
|
||||
#ifdef MOZ_TASK_TRACER
|
||||
nsCOMPtr<nsIRunnable> tracedRunnable = CreateTracedRunnable(event.take());
|
||||
nsCOMPtr<nsIRunnable> tracedRunnable = CreateTracedRunnable(event); // adds a ref
|
||||
(static_cast<TracedRunnable*>(tracedRunnable.get()))->DispatchTask();
|
||||
// XXX tracedRunnable will always leaked when we fail to disptch.
|
||||
event = tracedRunnable.forget();
|
||||
#endif
|
||||
|
||||
|
@ -611,14 +605,10 @@ nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFla
|
|||
// that to tell us when the event has been processed.
|
||||
|
||||
nsRefPtr<nsThreadSyncDispatch> wrapper =
|
||||
new nsThreadSyncDispatch(thread, event.take());
|
||||
new nsThreadSyncDispatch(thread, event.forget());
|
||||
nsresult rv = PutEvent(wrapper, aTarget); // hold a ref
|
||||
// Don't wait for the event to finish if we didn't dispatch it...
|
||||
if (NS_FAILED(rv)) {
|
||||
// PutEvent leaked the wrapper runnable object on failure, so we
|
||||
// explicitly release this object once for that. Note that this
|
||||
// object will be released again soon because it exits the scope.
|
||||
wrapper.get()->Release();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -626,13 +616,11 @@ nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFla
|
|||
while (wrapper->IsPending()) {
|
||||
NS_ProcessNextEvent(thread, true);
|
||||
}
|
||||
// NOTE that, unlike the behavior above, the event is not leaked by
|
||||
// this place, while it is possible that the result is an error.
|
||||
return wrapper->Result();
|
||||
}
|
||||
|
||||
NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
|
||||
return PutEvent(event.take(), aTarget);
|
||||
return PutEvent(event.forget(), aTarget);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -1182,6 +1170,20 @@ 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,6 +207,36 @@ 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,7 +12,6 @@
|
|||
#include "nsAutoPtr.h"
|
||||
#include "prinrval.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "nsThreadSyncDispatch.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/* -*- 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"
|
||||
#include "LeakRefPtr.h"
|
||||
|
||||
class nsThreadSyncDispatch : public nsRunnable
|
||||
{
|
||||
public:
|
||||
nsThreadSyncDispatch(nsIThread* aOrigin, already_AddRefed<nsIRunnable>&& aTask)
|
||||
: mOrigin(aOrigin)
|
||||
, mSyncTask(mozilla::Move(aTask))
|
||||
, mResult(NS_ERROR_NOT_INITIALIZED)
|
||||
{
|
||||
}
|
||||
|
||||
bool IsPending()
|
||||
{
|
||||
return !!mSyncTask;
|
||||
}
|
||||
|
||||
nsresult Result()
|
||||
{
|
||||
return mResult;
|
||||
}
|
||||
|
||||
private:
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
if (nsCOMPtr<nsIRunnable> task = mSyncTask.take()) {
|
||||
mResult = task->Run();
|
||||
// unblock the origin thread
|
||||
mOrigin->Dispatch(this, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIThread> mOrigin;
|
||||
// The task is leaked by default when Run() is not called, because
|
||||
// otherwise we may release it in an incorrect thread.
|
||||
mozilla::LeakRefPtr<nsIRunnable> mSyncTask;
|
||||
nsresult mResult;
|
||||
};
|
||||
|
||||
#endif // nsThreadSyncDispatch_h_
|
Загрузка…
Ссылка в новой задаче