Bug 1669214 - Part 5: Construct regular EventQueue using TC forwarding for the main thread. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D92454
This commit is contained in:
Bas Schouten 2020-10-06 13:21:35 +00:00
Родитель f6e295763f
Коммит 24a0a286fc
3 изменённых файлов: 9 добавлений и 10 удалений

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

@ -52,7 +52,8 @@ ThreadEventQueue<InnerQueueT>::ThreadEventQueue(UniquePtr<InnerQueueT> aQueue,
bool aIsMainThread)
: mBaseQueue(std::move(aQueue)),
mLock("ThreadEventQueue"),
mEventsAvailable(mLock, "EventsAvail") {
mEventsAvailable(mLock, "EventsAvail"),
mIsMainThread(aIsMainThread) {
if (aIsMainThread) {
TaskController::Get()->SetConditionVariable(&mEventsAvailable);
}
@ -84,7 +85,7 @@ bool ThreadEventQueue<InnerQueueT>::PutEventInternal(
// Check if the runnable wants to override the passed-in priority.
// Do this outside the lock, so runnables implemented in JS can QI
// (and possibly GC) outside of the lock.
if (InnerQueueT::SupportsPrioritization) {
if (mIsMainThread) {
auto* e = event.get(); // can't do_QueryInterface on LeakRefPtr.
if (nsCOMPtr<nsIRunnablePriority> runnablePrio = do_QueryInterface(e)) {
uint32_t prio = nsIRunnablePriority::PRIORITY_NORMAL;

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

@ -91,6 +91,7 @@ class ThreadEventQueue final : public SynchronizedEventQueue {
bool mEventsAreDoomed = false;
nsCOMPtr<nsIThreadObserver> mObserver;
bool mIsMainThread;
};
extern template class ThreadEventQueue<EventQueue>;

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

@ -379,15 +379,12 @@ nsresult nsThreadManager::Init() {
TaskController::Get()->SetIdleTaskManager(
new IdleTaskManager(idlePeriod.forget()));
// Create main thread queue and construct main thread.
UniquePtr<PrioritizedEventQueue> queue = MakeUnique<PrioritizedEventQueue>();
// Create main thread queue that forwards events to TaskController and
// construct main thread.
UniquePtr<EventQueue> queue = MakeUnique<EventQueue>(true);
PrioritizedEventQueue* prioritized = queue.get();
RefPtr<ThreadEventQueue<PrioritizedEventQueue>> synchronizedQueue =
new ThreadEventQueue<PrioritizedEventQueue>(std::move(queue), true);
prioritized->SetMutexRef(synchronizedQueue->MutexRef());
RefPtr<ThreadEventQueue<EventQueue>> synchronizedQueue =
new ThreadEventQueue<EventQueue>(std::move(queue), true);
mMainThread =
new nsThread(WrapNotNull(synchronizedQueue), nsThread::MAIN_THREAD, 0);