зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1154782 - Detemplatize nsIThread wrapper and move it into AbstractThread.cpp. r=jww
This commit is contained in:
Родитель
22739fb995
Коммит
9451263fde
|
@ -16,23 +16,28 @@ namespace mozilla {
|
|||
|
||||
StaticRefPtr<AbstractThread> sMainThread;
|
||||
|
||||
template<>
|
||||
nsresult
|
||||
AbstractThreadImpl<nsIThread>::Dispatch(already_AddRefed<nsIRunnable> aRunnable)
|
||||
class XPCOMThreadWrapper : public AbstractThread
|
||||
{
|
||||
MediaTaskQueue::AssertInTailDispatchIfNeeded();
|
||||
nsCOMPtr<nsIRunnable> r = aRunnable;
|
||||
return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
public:
|
||||
explicit XPCOMThreadWrapper(nsIThread* aTarget) : mTarget(aTarget) {}
|
||||
|
||||
template<>
|
||||
bool
|
||||
AbstractThreadImpl<nsIThread>::IsCurrentThreadIn()
|
||||
{
|
||||
bool in = NS_GetCurrentThread() == mTarget;
|
||||
MOZ_ASSERT_IF(in, MediaTaskQueue::GetCurrentQueue() == nullptr);
|
||||
return in;
|
||||
}
|
||||
virtual nsresult Dispatch(already_AddRefed<nsIRunnable> aRunnable) override
|
||||
{
|
||||
MediaTaskQueue::AssertInTailDispatchIfNeeded();
|
||||
nsCOMPtr<nsIRunnable> r = aRunnable;
|
||||
return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
virtual bool IsCurrentThreadIn() override
|
||||
{
|
||||
bool in = NS_GetCurrentThread() == mTarget;
|
||||
MOZ_ASSERT_IF(in, MediaTaskQueue::GetCurrentQueue() == nullptr);
|
||||
return in;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<nsIThread> mTarget;
|
||||
};
|
||||
|
||||
void
|
||||
AbstractThread::MaybeTailDispatch(already_AddRefed<nsIRunnable> aRunnable,
|
||||
|
@ -64,7 +69,7 @@ AbstractThread::InitStatics()
|
|||
nsCOMPtr<nsIThread> mainThread;
|
||||
NS_GetMainThread(getter_AddRefs(mainThread));
|
||||
MOZ_DIAGNOSTIC_ASSERT(mainThread);
|
||||
sMainThread = new AbstractThreadImpl<nsIThread>(mainThread.get());
|
||||
sMainThread = new XPCOMThreadWrapper(mainThread.get());
|
||||
ClearOnShutdown(&sMainThread);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,17 +50,6 @@ protected:
|
|||
virtual ~AbstractThread() {}
|
||||
};
|
||||
|
||||
template<typename TargetType>
|
||||
class AbstractThreadImpl : public AbstractThread
|
||||
{
|
||||
public:
|
||||
explicit AbstractThreadImpl(TargetType* aTarget) : mTarget(aTarget) {}
|
||||
virtual nsresult Dispatch(already_AddRefed<nsIRunnable> aRunnable);
|
||||
virtual bool IsCurrentThreadIn();
|
||||
private:
|
||||
nsRefPtr<TargetType> mTarget;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче