Bug 1281626 - part 3 - make various things accept already_AddRefed<nsIRunnable>; r=khuey

All of these things are called with the result of
NS_NewRunnableFunction, so we need to transition them over to a world
where NS_NewRunnableFunction returns something different.
This commit is contained in:
Nathan Froyd 2016-06-28 22:24:54 -04:00
Родитель f624e16333
Коммит 8b24c9d51c
5 изменённых файлов: 35 добавлений и 9 удалений

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

@ -18,8 +18,13 @@ QueueObject::~QueueObject() {}
void
QueueObject::Dispatch(nsIRunnable* aRunnable)
{
nsCOMPtr<nsIRunnable> runnable = aRunnable;
mThread->Dispatch(runnable.forget());
Dispatch(do_AddRef(aRunnable));
}
void
QueueObject::Dispatch(already_AddRefed<nsIRunnable> aRunnable)
{
mThread->Dispatch(Move(aRunnable));
}
bool

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

@ -21,6 +21,7 @@ public:
explicit QueueObject(RefPtr<AbstractThread> aThread);
~QueueObject();
void Dispatch(nsIRunnable* aRunnable);
void Dispatch(already_AddRefed<nsIRunnable> aRunnable);
bool OnThread();
AbstractThread* Thread();

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

@ -61,18 +61,26 @@ nsresult CacheIOThread::Init()
}
nsresult CacheIOThread::Dispatch(nsIRunnable* aRunnable, uint32_t aLevel)
{
return Dispatch(do_AddRef(aRunnable), aLevel);
}
nsresult CacheIOThread::Dispatch(already_AddRefed<nsIRunnable> aRunnable,
uint32_t aLevel)
{
NS_ENSURE_ARG(aLevel < LAST_LEVEL);
nsCOMPtr<nsIRunnable> runnable(aRunnable);
// Runnable is always expected to be non-null, hard null-check bellow.
MOZ_ASSERT(aRunnable);
MOZ_ASSERT(runnable);
MonitorAutoLock lock(mMonitor);
if (mShutdown && (PR_GetCurrentThread() != mThread))
return NS_ERROR_UNEXPECTED;
return DispatchInternal(aRunnable, aLevel);
return DispatchInternal(runnable.forget(), aLevel);
}
nsresult CacheIOThread::DispatchAfterPendingOpens(nsIRunnable* aRunnable)
@ -90,17 +98,20 @@ nsresult CacheIOThread::DispatchAfterPendingOpens(nsIRunnable* aRunnable)
mEventQueue[OPEN_PRIORITY].AppendElements(mEventQueue[OPEN]);
mEventQueue[OPEN].Clear();
return DispatchInternal(aRunnable, OPEN_PRIORITY);
return DispatchInternal(do_AddRef(aRunnable), OPEN_PRIORITY);
}
nsresult CacheIOThread::DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel)
nsresult CacheIOThread::DispatchInternal(already_AddRefed<nsIRunnable> aRunnable,
uint32_t aLevel)
{
if (NS_WARN_IF(!aRunnable))
nsCOMPtr<nsIRunnable> runnable(aRunnable);
if (NS_WARN_IF(!runnable))
return NS_ERROR_NULL_POINTER;
mMonitor.AssertCurrentThreadOwns();
mEventQueue[aLevel].AppendElement(aRunnable);
mEventQueue[aLevel].AppendElement(runnable.forget());
if (mLowestLevelWaiting > aLevel)
mLowestLevelWaiting = aLevel;

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

@ -49,6 +49,7 @@ public:
nsresult Init();
nsresult Dispatch(nsIRunnable* aRunnable, uint32_t aLevel);
nsresult Dispatch(already_AddRefed<nsIRunnable>, uint32_t aLevel);
// Makes sure that any previously posted event to OPEN or OPEN_PRIORITY
// levels (such as file opennings and dooms) are executed before aRunnable
// that is intended to evict stuff from the cache.
@ -81,7 +82,7 @@ private:
void ThreadFunc();
void LoopOneLevel(uint32_t aLevel);
bool EventsPending(uint32_t aLastLevel = LAST_LEVEL);
nsresult DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel);
nsresult DispatchInternal(already_AddRefed<nsIRunnable> aRunnable, uint32_t aLevel);
bool YieldInternal();
static CacheIOThread* sSelf;

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

@ -10,6 +10,7 @@
#include "nsThreadUtils.h"
#include "mozilla/AbstractThread.h"
#include "mozilla/Monitor.h"
#include "mozilla/Move.h"
namespace mozilla {
@ -39,6 +40,13 @@ public:
{
}
explicit SyncRunnable(already_AddRefed<nsIRunnable> aRunnable)
: mRunnable(Move(aRunnable))
, mMonitor("SyncRunnable")
, mDone(false)
{
}
void DispatchToThread(nsIEventTarget* aThread, bool aForceDispatch = false)
{
nsresult rv;