mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1646054 - P1. Remove EventTargetWrapper class. r=froydnj
We also establish the intent of bug 1602167 on the TaskQueue object Differential Revision: https://phabricator.services.mozilla.com/D80351
This commit is contained in:
parent
e1d7f7bcaf
commit
ea34205395
@ -1098,7 +1098,6 @@ class BackgroundRequestChild::PreprocessHelper final
|
||||
|
||||
const nsCOMPtr<nsIEventTarget> mOwningEventTarget;
|
||||
RefPtr<TaskQueue> mTaskQueue;
|
||||
nsCOMPtr<nsIEventTarget> mTaskQueueEventTarget;
|
||||
nsCOMPtr<nsIInputStream> mStream;
|
||||
UniquePtr<JSStructuredCloneData> mCloneData;
|
||||
BackgroundRequestChild* mActor;
|
||||
@ -2677,7 +2676,6 @@ nsresult BackgroundRequestChild::PreprocessHelper::Init(
|
||||
// in the correct order. This is not guaranteed in case we use the I/O thread
|
||||
// directly.
|
||||
mTaskQueue = MakeRefPtr<TaskQueue>(target.forget());
|
||||
mTaskQueueEventTarget = mTaskQueue->WrapAsEventTarget();
|
||||
|
||||
ErrorResult errorResult;
|
||||
|
||||
@ -2700,7 +2698,7 @@ nsresult BackgroundRequestChild::PreprocessHelper::Dispatch() {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mState == State::Initial);
|
||||
|
||||
nsresult rv = mTaskQueueEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
|
||||
nsresult rv = mTaskQueue->Dispatch(this, NS_DISPATCH_NORMAL);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -2729,7 +2727,7 @@ nsresult BackgroundRequestChild::PreprocessHelper::Start() {
|
||||
|
||||
nsCOMPtr<nsIAsyncFileMetadata> asyncFileMetadata = do_QueryInterface(mStream);
|
||||
if (asyncFileMetadata) {
|
||||
rv = asyncFileMetadata->AsyncFileMetadataWait(this, mTaskQueueEventTarget);
|
||||
rv = asyncFileMetadata->AsyncFileMetadataWait(this, mTaskQueue);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -2742,7 +2740,7 @@ nsresult BackgroundRequestChild::PreprocessHelper::Start() {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
rv = asyncStream->AsyncWait(this, 0, 0, mTaskQueueEventTarget);
|
||||
rv = asyncStream->AsyncWait(this, 0, 0, mTaskQueue);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
#include "MediaInfo.h"
|
||||
#include "TimeUnits.h"
|
||||
#include "VideoLimits.h"
|
||||
#include "mozilla/gfx/Point.h" // for gfx::IntSize
|
||||
#include "mozilla/gfx/Types.h"
|
||||
#include "mozilla/AbstractThread.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
@ -20,12 +18,14 @@
|
||||
#include "mozilla/ReentrantMonitor.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/SharedThreadPool.h"
|
||||
#include "mozilla/TaskQueue.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/gfx/Point.h" // for gfx::IntSize
|
||||
#include "mozilla/gfx/Types.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsINamed.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
#include "nsThreadUtils.h"
|
||||
#include "prtime.h"
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class TaskQueue;
|
||||
class TaskDispatcher;
|
||||
|
||||
/*
|
||||
|
@ -6,57 +6,10 @@
|
||||
|
||||
#include "mozilla/TaskQueue.h"
|
||||
|
||||
#include "nsISerialEventTarget.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class TaskQueue::EventTargetWrapper final : public nsISerialEventTarget {
|
||||
RefPtr<TaskQueue> mTaskQueue;
|
||||
|
||||
~EventTargetWrapper() = default;
|
||||
|
||||
public:
|
||||
explicit EventTargetWrapper(TaskQueue* aTaskQueue) : mTaskQueue(aTaskQueue) {
|
||||
MOZ_ASSERT(mTaskQueue);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
DispatchFromScript(nsIRunnable* aEvent, uint32_t aFlags) override {
|
||||
nsCOMPtr<nsIRunnable> ref = aEvent;
|
||||
return Dispatch(ref.forget(), aFlags);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags) override {
|
||||
nsCOMPtr<nsIRunnable> runnable = aEvent;
|
||||
MonitorAutoLock mon(mTaskQueue->mQueueMonitor);
|
||||
return mTaskQueue->DispatchLocked(/* passed by ref */ runnable, aFlags,
|
||||
NormalDispatch);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
DelayedDispatch(already_AddRefed<nsIRunnable>, uint32_t aFlags) override {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
IsOnCurrentThread(bool* aResult) override {
|
||||
*aResult = mTaskQueue->IsCurrentThreadIn();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(bool)
|
||||
IsOnCurrentThreadInfallible() override {
|
||||
return mTaskQueue->mTarget->IsOnCurrentThread();
|
||||
}
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(TaskQueue::EventTargetWrapper, nsIEventTarget,
|
||||
nsISerialEventTarget)
|
||||
|
||||
TaskQueue::TaskQueue(already_AddRefed<nsIEventTarget> aTarget,
|
||||
const char* aName, bool aRequireTailDispatch,
|
||||
bool aRetainFlags)
|
||||
@ -180,11 +133,6 @@ bool TaskQueue::IsCurrentThreadIn() const {
|
||||
return in;
|
||||
}
|
||||
|
||||
already_AddRefed<nsISerialEventTarget> TaskQueue::WrapAsEventTarget() {
|
||||
nsCOMPtr<nsISerialEventTarget> ref = new EventTargetWrapper(this);
|
||||
return ref.forget();
|
||||
}
|
||||
|
||||
nsresult TaskQueue::Runner::Run() {
|
||||
TaskStruct event;
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "mozilla/AbstractThread.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
@ -18,9 +19,6 @@
|
||||
#include "nsIDirectTaskDispatcher.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
class nsIEventTarget;
|
||||
class nsIRunnable;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
typedef MozPromise<bool, bool, false> ShutdownPromise;
|
||||
@ -66,6 +64,20 @@ class TaskQueue : public AbstractThread, public nsIDirectTaskDispatcher {
|
||||
|
||||
TaskDispatcher& TailDispatcher() override;
|
||||
|
||||
NS_IMETHOD Dispatch(already_AddRefed<nsIRunnable> aEvent,
|
||||
uint32_t aFlags) override {
|
||||
nsCOMPtr<nsIRunnable> runnable = aEvent;
|
||||
{
|
||||
MonitorAutoLock mon(mQueueMonitor);
|
||||
return DispatchLocked(/* passed by ref */ runnable, aFlags,
|
||||
NormalDispatch);
|
||||
}
|
||||
// If the ownership of |r| is not transferred in DispatchLocked() due to
|
||||
// dispatch failure, it will be deleted here outside the lock. We do so
|
||||
// since the destructor of the runnable might access TaskQueue and result
|
||||
// in deadlocks.
|
||||
}
|
||||
|
||||
[[nodiscard]] nsresult Dispatch(
|
||||
already_AddRefed<nsIRunnable> aRunnable,
|
||||
DispatchReason aReason = NormalDispatch) override {
|
||||
@ -80,8 +92,8 @@ class TaskQueue : public AbstractThread, public nsIDirectTaskDispatcher {
|
||||
// in deadlocks.
|
||||
}
|
||||
|
||||
// Prevent a GCC warning about the other overload of Dispatch being hidden.
|
||||
using AbstractThread::Dispatch;
|
||||
// So we can access nsIEventTarget::Dispatch(nsIRunnable*, uint32_t aFlags)
|
||||
using nsIEventTarget::Dispatch;
|
||||
|
||||
// Puts the queue in a shutdown state and returns immediately. The queue will
|
||||
// remain alive at least until all the events are drained, because the Runners
|
||||
@ -104,10 +116,6 @@ class TaskQueue : public AbstractThread, public nsIDirectTaskDispatcher {
|
||||
// the task queue.
|
||||
bool IsCurrentThreadIn() const override;
|
||||
|
||||
// Create a new nsIEventTarget wrapper object that dispatches to this
|
||||
// TaskQueue.
|
||||
already_AddRefed<nsISerialEventTarget> WrapAsEventTarget();
|
||||
|
||||
protected:
|
||||
virtual ~TaskQueue();
|
||||
|
||||
|
@ -187,11 +187,9 @@ BackgroundEventTarget::CreateBackgroundTaskQueue(const char* aName) {
|
||||
RefPtr<TaskQueue> queue = new TaskQueue(do_AddRef(this), aName,
|
||||
/*aSupportsTailDispatch=*/false,
|
||||
/*aRetainFlags=*/true);
|
||||
nsCOMPtr<nsISerialEventTarget> target(queue->WrapAsEventTarget());
|
||||
mTaskQueues.AppendElement(queue);
|
||||
|
||||
mTaskQueues.AppendElement(queue.forget());
|
||||
|
||||
return target.forget();
|
||||
return queue.forget();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
Loading…
Reference in New Issue
Block a user