mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out 6 changesets (bug 1186745) for android Cpp failures
Backed out changeset 237a6acf0709 (bug 1186745) Backed out changeset 7b530871783a (bug 1186745) Backed out changeset 73f73b531fc8 (bug 1186745) Backed out changeset e36909748ddf (bug 1186745) Backed out changeset 3a31df8787f0 (bug 1186745) Backed out changeset df9cb8f5f0a5 (bug 1186745)
This commit is contained in:
parent
cfcc5a4b84
commit
9e15a76411
@ -75,8 +75,7 @@ const PRTime GetStartTime();
|
|||||||
|
|
||||||
Task* CreateTracedTask(Task* aTask);
|
Task* CreateTracedTask(Task* aTask);
|
||||||
|
|
||||||
already_AddRefed<nsIRunnable>
|
already_AddRefed<nsIRunnable> CreateTracedRunnable(nsIRunnable* aRunnable);
|
||||||
CreateTracedRunnable(already_AddRefed<nsIRunnable>&& aRunnable);
|
|
||||||
|
|
||||||
// Free the TraceInfo allocated on a thread's TLS. Currently we are wrapping
|
// 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
|
// tasks running on nsThreads and base::thread, so FreeTraceInfo is called at
|
||||||
|
@ -90,9 +90,9 @@ TracedTaskCommon::ClearTLSTraceInfo()
|
|||||||
/**
|
/**
|
||||||
* Implementation of class TracedRunnable.
|
* Implementation of class TracedRunnable.
|
||||||
*/
|
*/
|
||||||
TracedRunnable::TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj)
|
TracedRunnable::TracedRunnable(nsIRunnable* aOriginalObj)
|
||||||
: TracedTaskCommon()
|
: TracedTaskCommon()
|
||||||
, mOriginalObj(Move(aOriginalObj))
|
, mOriginalObj(aOriginalObj)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
LogVirtualTablePtr(mTaskId, mSourceEventId, *(int**)(aOriginalObj));
|
LogVirtualTablePtr(mTaskId, mSourceEventId, *(int**)(aOriginalObj));
|
||||||
@ -148,9 +148,9 @@ TracedTask::Run()
|
|||||||
* nsIRunnable object, aRunnable.
|
* nsIRunnable object, aRunnable.
|
||||||
*/
|
*/
|
||||||
already_AddRefed<nsIRunnable>
|
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();
|
return runnable.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class TracedRunnable : public TracedTaskCommon
|
|||||||
public:
|
public:
|
||||||
NS_DECL_NSIRUNNABLE
|
NS_DECL_NSIRUNNABLE
|
||||||
|
|
||||||
TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj);
|
TracedRunnable(nsIRunnable* aOriginalObj);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~TracedRunnable();
|
virtual ~TracedRunnable();
|
||||||
|
@ -106,7 +106,6 @@ if CONFIG['_MSC_VER']:
|
|||||||
|
|
||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'../build',
|
'../build',
|
||||||
'../threads',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if CONFIG['ENABLE_TESTS']:
|
if CONFIG['ENABLE_TESTS']:
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/Likely.h"
|
#include "mozilla/Likely.h"
|
||||||
#include "LeakRefPtr.h"
|
|
||||||
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
# include "nsThreadManager.h"
|
# include "nsThreadManager.h"
|
||||||
@ -28,8 +27,6 @@ using mozilla::IsVistaOrLater;
|
|||||||
#include <pratom.h>
|
#include <pratom.h>
|
||||||
#include <prthread.h>
|
#include <prthread.h>
|
||||||
|
|
||||||
using namespace mozilla;
|
|
||||||
|
|
||||||
#ifndef XPCOM_GLUE_AVOID_NSPR
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsRunnable, nsIRunnable)
|
NS_IMPL_ISUPPORTS(nsRunnable, nsIRunnable)
|
||||||
@ -142,11 +139,13 @@ NS_IsMainThread()
|
|||||||
}
|
}
|
||||||
#endif
|
#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_METHOD
|
||||||
NS_DispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent)
|
NS_DispatchToCurrentThread(nsIRunnable* aEvent)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsCOMPtr<nsIRunnable> deathGrip = aEvent;
|
||||||
nsCOMPtr<nsIRunnable> event(aEvent);
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
nsIThread* thread = NS_GetCurrentThread();
|
nsIThread* thread = NS_GetCurrentThread();
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
@ -154,47 +153,28 @@ NS_DispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
nsCOMPtr<nsIThread> thread;
|
nsCOMPtr<nsIThread> thread;
|
||||||
rv = NS_GetCurrentThread(getter_AddRefs(thread));
|
nsresult rv = NS_GetCurrentThread(getter_AddRefs(thread));
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// To keep us from leaking the runnable if dispatch method fails,
|
return thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
|
||||||
// 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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_METHOD
|
NS_METHOD
|
||||||
NS_DispatchToMainThread(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aDispatchFlags)
|
NS_DispatchToMainThread(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aDispatchFlags)
|
||||||
{
|
{
|
||||||
LeakRefPtr<nsIRunnable> event(Move(aEvent));
|
nsCOMPtr<nsIRunnable> event(aEvent);
|
||||||
nsCOMPtr<nsIThread> thread;
|
nsCOMPtr<nsIThread> thread;
|
||||||
nsresult rv = NS_GetMainThread(getter_AddRefs(thread));
|
nsresult rv = NS_GetMainThread(getter_AddRefs(thread));
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
NS_ASSERTION(false, "Failed NS_DispatchToMainThread() in shutdown; leaking");
|
NS_ASSERTION(false, "Failed NS_DispatchToMainThread() in shutdown; leaking");
|
||||||
// NOTE: if you stop leaking here, adjust Promise::MaybeReportRejected(),
|
// NOTE: if you stop leaking here, adjust Promise::MaybeReportRejected(),
|
||||||
// which assumes a leak here, or split into leaks and no-leaks versions
|
// 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
|
// 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.
|
* If event is null.
|
||||||
*/
|
*/
|
||||||
extern NS_METHOD NS_DispatchToCurrentThread(nsIRunnable* aEvent);
|
extern NS_METHOD NS_DispatchToCurrentThread(nsIRunnable* aEvent);
|
||||||
extern NS_METHOD
|
|
||||||
NS_DispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch the given event to the main thread.
|
* Dispatch the given event to the main thread.
|
||||||
|
@ -38,7 +38,6 @@ DEFINES['XPCOM_GLUE'] = True
|
|||||||
|
|
||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'../../build',
|
'../../build',
|
||||||
'../../threads',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
|
# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
|
||||||
|
@ -30,7 +30,6 @@ DEFINES['XPCOM_GLUE'] = True
|
|||||||
|
|
||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'../../../build',
|
'../../../build',
|
||||||
'../../../threads',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Statically link to the CRT on Windows
|
# Statically link to the CRT on Windows
|
||||||
|
@ -28,7 +28,6 @@ if CONFIG['_MSC_VER']:
|
|||||||
|
|
||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'../../build',
|
'../../build',
|
||||||
'../../threads',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Statically link to the CRT on Windows
|
# 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 it's 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* MOZ_OWNING_REF mRawPtr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
#endif // LeakRefPtr_h
|
|
@ -60,10 +60,7 @@ interface nsIEventTarget : nsISupports
|
|||||||
* any thread, and it may be called re-entrantly.
|
* any thread, and it may be called re-entrantly.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* The alreadyAddRefed<> event to dispatch.
|
* 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.
|
|
||||||
* @param flags
|
* @param flags
|
||||||
* The flags modifying event dispatch. The flags are described in detail
|
* The flags modifying event dispatch. The flags are described in detail
|
||||||
* below.
|
* below.
|
||||||
|
@ -36,8 +36,6 @@
|
|||||||
#include "nsXPCOMPrivate.h"
|
#include "nsXPCOMPrivate.h"
|
||||||
#include "mozilla/ChaosMode.h"
|
#include "mozilla/ChaosMode.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "mozilla/TimeStamp.h"
|
||||||
#include "nsThreadSyncDispatch.h"
|
|
||||||
#include "LeakRefPtr.h"
|
|
||||||
|
|
||||||
#ifdef MOZ_CRASHREPORTER
|
#ifdef MOZ_CRASHREPORTER
|
||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
@ -543,9 +541,6 @@ nsThread::PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget)
|
|||||||
nsresult
|
nsresult
|
||||||
nsThread::PutEvent(already_AddRefed<nsIRunnable>&& aEvent, nsNestedEventTarget* aTarget)
|
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;
|
nsCOMPtr<nsIThreadObserver> obs;
|
||||||
|
|
||||||
#ifdef MOZ_NUWA_PROCESS
|
#ifdef MOZ_NUWA_PROCESS
|
||||||
@ -559,9 +554,11 @@ nsThread::PutEvent(already_AddRefed<nsIRunnable>&& aEvent, nsNestedEventTarget*
|
|||||||
nsChainedEventQueue* queue = aTarget ? aTarget->mQueue : &mEventsRoot;
|
nsChainedEventQueue* queue = aTarget ? aTarget->mQueue : &mEventsRoot;
|
||||||
if (!queue || (queue == &mEventsRoot && mEventsAreDoomed)) {
|
if (!queue || (queue == &mEventsRoot && mEventsAreDoomed)) {
|
||||||
NS_WARNING("An event was posted to a thread that will never run it (rejected)");
|
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
|
// 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
|
// 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,
|
nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFlags,
|
||||||
nsNestedEventTarget* aTarget)
|
nsNestedEventTarget* aTarget)
|
||||||
{
|
{
|
||||||
// We want to leak the reference when we fail to dispatch it, so that
|
nsCOMPtr<nsIRunnable> event(aEvent);
|
||||||
// we won't release the event in a wrong thread.
|
|
||||||
LeakRefPtr<nsIRunnable> event(Move(aEvent));
|
|
||||||
if (NS_WARN_IF(!event)) {
|
if (NS_WARN_IF(!event)) {
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
@ -594,9 +589,8 @@ nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFla
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOZ_TASK_TRACER
|
#ifdef MOZ_TASK_TRACER
|
||||||
nsCOMPtr<nsIRunnable> tracedRunnable = CreateTracedRunnable(event.take());
|
nsCOMPtr<nsIRunnable> tracedRunnable = CreateTracedRunnable(event); // adds a ref
|
||||||
(static_cast<TracedRunnable*>(tracedRunnable.get()))->DispatchTask();
|
(static_cast<TracedRunnable*>(tracedRunnable.get()))->DispatchTask();
|
||||||
// XXX tracedRunnable will always leaked when we fail to disptch.
|
|
||||||
event = tracedRunnable.forget();
|
event = tracedRunnable.forget();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -611,14 +605,10 @@ nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFla
|
|||||||
// that to tell us when the event has been processed.
|
// that to tell us when the event has been processed.
|
||||||
|
|
||||||
nsRefPtr<nsThreadSyncDispatch> wrapper =
|
nsRefPtr<nsThreadSyncDispatch> wrapper =
|
||||||
new nsThreadSyncDispatch(thread, event.take());
|
new nsThreadSyncDispatch(thread, event.forget());
|
||||||
nsresult rv = PutEvent(wrapper, aTarget); // hold a ref
|
nsresult rv = PutEvent(wrapper, aTarget); // hold a ref
|
||||||
// Don't wait for the event to finish if we didn't dispatch it...
|
// Don't wait for the event to finish if we didn't dispatch it...
|
||||||
if (NS_FAILED(rv)) {
|
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;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,13 +616,11 @@ nsThread::DispatchInternal(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aFla
|
|||||||
while (wrapper->IsPending()) {
|
while (wrapper->IsPending()) {
|
||||||
NS_ProcessNextEvent(thread, true);
|
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();
|
return wrapper->Result();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
|
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_IMPL_ISUPPORTS(nsThread::nsNestedEventTarget, nsIEventTarget)
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -207,6 +207,36 @@ protected:
|
|||||||
MainThreadFlag mIsMainThread;
|
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 \
|
#if defined(XP_UNIX) && !defined(ANDROID) && !defined(DEBUG) && HAVE_UALARM \
|
||||||
&& defined(_GNU_SOURCE)
|
&& defined(_GNU_SOURCE)
|
||||||
# define MOZ_CANARY
|
# define MOZ_CANARY
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "nsAutoPtr.h"
|
#include "nsAutoPtr.h"
|
||||||
#include "prinrval.h"
|
#include "prinrval.h"
|
||||||
#include "mozilla/Logging.h"
|
#include "mozilla/Logging.h"
|
||||||
#include "nsThreadSyncDispatch.h"
|
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -1,54 +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();
|
|
||||||
// We must release the task here to ensure that when the original
|
|
||||||
// thread is unblocked, this task has been released.
|
|
||||||
task = nullptr;
|
|
||||||
// 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_
|
|
Loading…
Reference in New Issue
Block a user