зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 00f8c8fde8ca (bug 1222101) for build bustage CLOSED TREE
MozReview-Commit-ID: F6PINhcfsF4
This commit is contained in:
Родитель
7d22a5cb40
Коммит
dd58e668a4
|
@ -89,7 +89,7 @@ MessageLoop* MessageLoop::current() {
|
||||||
|
|
||||||
static mozilla::Atomic<int32_t> message_loop_id_seq(0);
|
static mozilla::Atomic<int32_t> message_loop_id_seq(0);
|
||||||
|
|
||||||
MessageLoop::MessageLoop(Type type, nsIThread* aThread)
|
MessageLoop::MessageLoop(Type type)
|
||||||
: type_(type),
|
: type_(type),
|
||||||
id_(++message_loop_id_seq),
|
id_(++message_loop_id_seq),
|
||||||
nestable_tasks_allowed_(true),
|
nestable_tasks_allowed_(true),
|
||||||
|
@ -107,11 +107,9 @@ MessageLoop::MessageLoop(Type type, nsIThread* aThread)
|
||||||
|
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case TYPE_MOZILLA_PARENT:
|
case TYPE_MOZILLA_PARENT:
|
||||||
MOZ_RELEASE_ASSERT(!aThread);
|
pump_ = new mozilla::ipc::MessagePump();
|
||||||
pump_ = new mozilla::ipc::MessagePump(aThread);
|
|
||||||
return;
|
return;
|
||||||
case TYPE_MOZILLA_CHILD:
|
case TYPE_MOZILLA_CHILD:
|
||||||
MOZ_RELEASE_ASSERT(!aThread);
|
|
||||||
pump_ = new mozilla::ipc::MessagePumpForChildProcess();
|
pump_ = new mozilla::ipc::MessagePumpForChildProcess();
|
||||||
// There is a MessageLoop Run call from XRE_InitChildProcess
|
// There is a MessageLoop Run call from XRE_InitChildProcess
|
||||||
// and another one from MessagePumpForChildProcess. The one
|
// and another one from MessagePumpForChildProcess. The one
|
||||||
|
@ -121,11 +119,11 @@ MessageLoop::MessageLoop(Type type, nsIThread* aThread)
|
||||||
run_depth_base_ = 2;
|
run_depth_base_ = 2;
|
||||||
return;
|
return;
|
||||||
case TYPE_MOZILLA_NONMAINTHREAD:
|
case TYPE_MOZILLA_NONMAINTHREAD:
|
||||||
pump_ = new mozilla::ipc::MessagePumpForNonMainThreads(aThread);
|
pump_ = new mozilla::ipc::MessagePumpForNonMainThreads();
|
||||||
return;
|
return;
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
case TYPE_MOZILLA_NONMAINUITHREAD:
|
case TYPE_MOZILLA_NONMAINUITHREAD:
|
||||||
pump_ = new mozilla::ipc::MessagePumpForNonMainUIThreads(aThread);
|
pump_ = new mozilla::ipc::MessagePumpForNonMainUIThreads();
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
#include "nsAutoPtr.h"
|
#include "nsAutoPtr.h"
|
||||||
|
|
||||||
class nsIThread;
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
|
@ -225,7 +223,7 @@ public:
|
||||||
|
|
||||||
// Normally, it is not necessary to instantiate a MessageLoop. Instead, it
|
// Normally, it is not necessary to instantiate a MessageLoop. Instead, it
|
||||||
// is typical to make use of the current thread's MessageLoop instance.
|
// is typical to make use of the current thread's MessageLoop instance.
|
||||||
explicit MessageLoop(Type type = TYPE_DEFAULT, nsIThread* aThread = nullptr);
|
explicit MessageLoop(Type type = TYPE_DEFAULT);
|
||||||
~MessageLoop();
|
~MessageLoop();
|
||||||
|
|
||||||
// Returns the type passed to the constructor.
|
// Returns the type passed to the constructor.
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "base/waitable_event.h"
|
#include "base/waitable_event.h"
|
||||||
#include "GeckoProfiler.h"
|
#include "GeckoProfiler.h"
|
||||||
#include "mozilla/IOInterposer.h"
|
#include "mozilla/IOInterposer.h"
|
||||||
#include "nsThreadUtils.h"
|
|
||||||
|
|
||||||
#ifdef MOZ_TASK_TRACER
|
#ifdef MOZ_TASK_TRACER
|
||||||
#include "GeckoTaskTracer.h"
|
#include "GeckoTaskTracer.h"
|
||||||
|
@ -152,8 +151,7 @@ void Thread::ThreadMain() {
|
||||||
mozilla::IOInterposer::RegisterCurrentThread();
|
mozilla::IOInterposer::RegisterCurrentThread();
|
||||||
|
|
||||||
// The message loop for this thread.
|
// The message loop for this thread.
|
||||||
MessageLoop message_loop(startup_data_->options.message_loop_type,
|
MessageLoop message_loop(startup_data_->options.message_loop_type);
|
||||||
NS_GetCurrentThread());
|
|
||||||
|
|
||||||
// Complete the initialization of our Thread object.
|
// Complete the initialization of our Thread object.
|
||||||
thread_id_ = PlatformThread::CurrentId();
|
thread_id_ = PlatformThread::CurrentId();
|
||||||
|
|
|
@ -66,8 +66,8 @@ private:
|
||||||
} /* namespace ipc */
|
} /* namespace ipc */
|
||||||
} /* namespace mozilla */
|
} /* namespace mozilla */
|
||||||
|
|
||||||
MessagePump::MessagePump(nsIThread* aThread)
|
MessagePump::MessagePump()
|
||||||
: mThread(aThread)
|
: mThread(nullptr)
|
||||||
{
|
{
|
||||||
mDoWorkEvent = new DoWorkRunnable(this);
|
mDoWorkEvent = new DoWorkRunnable(this);
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,11 @@ void
|
||||||
MessagePump::Run(MessagePump::Delegate* aDelegate)
|
MessagePump::Run(MessagePump::Delegate* aDelegate)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(keep_running_);
|
MOZ_ASSERT(keep_running_);
|
||||||
MOZ_RELEASE_ASSERT(NS_IsMainThread(),
|
MOZ_ASSERT(NS_IsMainThread(),
|
||||||
"Use mozilla::ipc::MessagePumpForNonMainThreads instead!");
|
"Use mozilla::ipc::MessagePumpForNonMainThreads instead!");
|
||||||
MOZ_RELEASE_ASSERT(!mThread);
|
|
||||||
|
|
||||||
nsIThread* thisThread = NS_GetCurrentThread();
|
mThread = NS_GetCurrentThread();
|
||||||
MOZ_ASSERT(thisThread);
|
MOZ_ASSERT(mThread);
|
||||||
|
|
||||||
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
|
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
|
||||||
MOZ_ASSERT(mDelayedWorkTimer);
|
MOZ_ASSERT(mDelayedWorkTimer);
|
||||||
|
@ -95,7 +94,7 @@ MessagePump::Run(MessagePump::Delegate* aDelegate)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
autoReleasePool.Recycle();
|
autoReleasePool.Recycle();
|
||||||
|
|
||||||
bool did_work = NS_ProcessNextEvent(thisThread, false) ? true : false;
|
bool did_work = NS_ProcessNextEvent(mThread, false) ? true : false;
|
||||||
if (!keep_running_)
|
if (!keep_running_)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ if (did_work && delayed_work_time_.is_null()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// This will either sleep or process an event.
|
// This will either sleep or process an event.
|
||||||
NS_ProcessNextEvent(thisThread, true);
|
NS_ProcessNextEvent(mThread, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOZ_NUWA_PROCESS
|
#ifdef MOZ_NUWA_PROCESS
|
||||||
|
@ -144,7 +143,8 @@ MessagePump::ScheduleWork()
|
||||||
// Make sure the event loop wakes up.
|
// Make sure the event loop wakes up.
|
||||||
if (mThread) {
|
if (mThread) {
|
||||||
mThread->Dispatch(mDoWorkEvent, NS_DISPATCH_NORMAL);
|
mThread->Dispatch(mDoWorkEvent, NS_DISPATCH_NORMAL);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Some things (like xpcshell) don't use the app shell and so Run hasn't
|
// Some things (like xpcshell) don't use the app shell and so Run hasn't
|
||||||
// been called. We still need to wake up the main thread.
|
// been called. We still need to wake up the main thread.
|
||||||
NS_DispatchToMainThread(mDoWorkEvent);
|
NS_DispatchToMainThread(mDoWorkEvent);
|
||||||
|
@ -169,11 +169,6 @@ MessagePump::ScheduleDelayedWork(const base::TimeTicks& aDelayedTime)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// To avoid racing on mDelayedWorkTimer, we need to be on the same thread as
|
|
||||||
// ::Run().
|
|
||||||
MOZ_RELEASE_ASSERT(NS_GetCurrentThread() == mThread ||
|
|
||||||
(!mThread && NS_IsMainThread()));
|
|
||||||
|
|
||||||
if (!mDelayedWorkTimer) {
|
if (!mDelayedWorkTimer) {
|
||||||
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
|
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
|
||||||
if (!mDelayedWorkTimer) {
|
if (!mDelayedWorkTimer) {
|
||||||
|
@ -304,21 +299,21 @@ void
|
||||||
MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate* aDelegate)
|
MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate* aDelegate)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(keep_running_);
|
MOZ_ASSERT(keep_running_);
|
||||||
MOZ_RELEASE_ASSERT(!NS_IsMainThread(), "Use mozilla::ipc::MessagePump instead!");
|
MOZ_ASSERT(!NS_IsMainThread(), "Use mozilla::ipc::MessagePump instead!");
|
||||||
|
|
||||||
nsIThread* thread = NS_GetCurrentThread();
|
mThread = NS_GetCurrentThread();
|
||||||
MOZ_RELEASE_ASSERT(mThread == thread);
|
MOZ_ASSERT(mThread);
|
||||||
|
|
||||||
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
|
mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
|
||||||
MOZ_ASSERT(mDelayedWorkTimer);
|
MOZ_ASSERT(mDelayedWorkTimer);
|
||||||
|
|
||||||
if (NS_FAILED(mDelayedWorkTimer->SetTarget(thread))) {
|
if (NS_FAILED(mDelayedWorkTimer->SetTarget(mThread))) {
|
||||||
MOZ_CRASH("Failed to set timer target!");
|
MOZ_CRASH("Failed to set timer target!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chromium event notifications to be processed will be received by this
|
// Chromium event notifications to be processed will be received by this
|
||||||
// event loop as a DoWorkRunnables via ScheduleWork. Chromium events that
|
// event loop as a DoWorkRunnables via ScheduleWork. Chromium events that
|
||||||
// were received before our thread is valid, however, will not generate
|
// were received before our mThread is valid, however, will not generate
|
||||||
// runnable wrappers. We must process any of these before we enter this
|
// runnable wrappers. We must process any of these before we enter this
|
||||||
// loop, or we will forever have unprocessed chromium messages in our queue.
|
// loop, or we will forever have unprocessed chromium messages in our queue.
|
||||||
//
|
//
|
||||||
|
@ -334,7 +329,7 @@ MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate* aDelegate)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
autoReleasePool.Recycle();
|
autoReleasePool.Recycle();
|
||||||
|
|
||||||
bool didWork = NS_ProcessNextEvent(thread, false) ? true : false;
|
bool didWork = NS_ProcessNextEvent(mThread, false) ? true : false;
|
||||||
if (!keep_running_) {
|
if (!keep_running_) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +358,7 @@ MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate* aDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will either sleep or process an event.
|
// This will either sleep or process an event.
|
||||||
NS_ProcessNextEvent(thread, true);
|
NS_ProcessNextEvent(mThread, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDelayedWorkTimer->Cancel();
|
mDelayedWorkTimer->Cancel();
|
||||||
|
@ -377,19 +372,16 @@ NS_IMPL_QUERY_INTERFACE(MessagePumpForNonMainUIThreads, nsIThreadObserver)
|
||||||
|
|
||||||
#define CHECK_QUIT_STATE { if (state_->should_quit) { break; } }
|
#define CHECK_QUIT_STATE { if (state_->should_quit) { break; } }
|
||||||
|
|
||||||
void
|
void MessagePumpForNonMainUIThreads::DoRunLoop()
|
||||||
MessagePumpForNonMainUIThreads::DoRunLoop()
|
|
||||||
{
|
{
|
||||||
MOZ_RELEASE_ASSERT(!NS_IsMainThread(), "Use mozilla::ipc::MessagePump instead!");
|
|
||||||
|
|
||||||
// If this is a chromium thread and no nsThread is associated
|
// If this is a chromium thread and no nsThread is associated
|
||||||
// with it, this call will create a new nsThread.
|
// with it, this call will create a new nsThread.
|
||||||
nsIThread* thread = NS_GetCurrentThread();
|
mThread = NS_GetCurrentThread();
|
||||||
MOZ_ASSERT(thread);
|
MOZ_ASSERT(mThread);
|
||||||
|
|
||||||
// Set the main thread observer so we can wake up when
|
// Set the main thread observer so we can wake up when
|
||||||
// xpcom events need to get processed.
|
// xpcom events need to get processed.
|
||||||
nsCOMPtr<nsIThreadInternal> ti(do_QueryInterface(thread));
|
nsCOMPtr<nsIThreadInternal> ti(do_QueryInterface(mThread));
|
||||||
MOZ_ASSERT(ti);
|
MOZ_ASSERT(ti);
|
||||||
ti->SetObserver(this);
|
ti->SetObserver(this);
|
||||||
|
|
||||||
|
@ -397,7 +389,7 @@ MessagePumpForNonMainUIThreads::DoRunLoop()
|
||||||
for (;;) {
|
for (;;) {
|
||||||
autoReleasePool.Recycle();
|
autoReleasePool.Recycle();
|
||||||
|
|
||||||
bool didWork = NS_ProcessNextEvent(thread, false);
|
bool didWork = NS_ProcessNextEvent(mThread, false);
|
||||||
|
|
||||||
didWork |= ProcessNextWindowsMessage();
|
didWork |= ProcessNextWindowsMessage();
|
||||||
CHECK_QUIT_STATE
|
CHECK_QUIT_STATE
|
||||||
|
@ -419,7 +411,7 @@ MessagePumpForNonMainUIThreads::DoRunLoop()
|
||||||
CHECK_QUIT_STATE
|
CHECK_QUIT_STATE
|
||||||
|
|
||||||
SetInWait();
|
SetInWait();
|
||||||
bool hasWork = NS_HasPendingEvents(thread);
|
bool hasWork = NS_HasPendingEvents(mThread);
|
||||||
if (didWork || hasWork) {
|
if (didWork || hasWork) {
|
||||||
ClearInWait();
|
ClearInWait();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class MessagePump : public base::MessagePumpDefault
|
||||||
friend class DoWorkRunnable;
|
friend class DoWorkRunnable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MessagePump(nsIThread* aThread);
|
MessagePump();
|
||||||
|
|
||||||
// From base::MessagePump.
|
// From base::MessagePump.
|
||||||
virtual void
|
virtual void
|
||||||
|
@ -56,11 +56,10 @@ private:
|
||||||
void DoDelayedWork(base::MessagePump::Delegate* aDelegate);
|
void DoDelayedWork(base::MessagePump::Delegate* aDelegate);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsIThread* mThread;
|
|
||||||
|
|
||||||
// mDelayedWorkTimer and mThread are set in Run() by this class or its
|
// mDelayedWorkTimer and mThread are set in Run() by this class or its
|
||||||
// subclasses.
|
// subclasses.
|
||||||
nsCOMPtr<nsITimer> mDelayedWorkTimer;
|
nsCOMPtr<nsITimer> mDelayedWorkTimer;
|
||||||
|
nsIThread* mThread;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Only accessed by this class.
|
// Only accessed by this class.
|
||||||
|
@ -71,8 +70,7 @@ class MessagePumpForChildProcess final: public MessagePump
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessagePumpForChildProcess()
|
MessagePumpForChildProcess()
|
||||||
: MessagePump(nullptr),
|
: mFirstRun(true)
|
||||||
mFirstRun(true)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void Run(base::MessagePump::Delegate* aDelegate) override;
|
virtual void Run(base::MessagePump::Delegate* aDelegate) override;
|
||||||
|
@ -87,8 +85,7 @@ private:
|
||||||
class MessagePumpForNonMainThreads final : public MessagePump
|
class MessagePumpForNonMainThreads final : public MessagePump
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessagePumpForNonMainThreads(nsIThread* aThread)
|
MessagePumpForNonMainThreads()
|
||||||
: MessagePump(aThread)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void Run(base::MessagePump::Delegate* aDelegate) override;
|
virtual void Run(base::MessagePump::Delegate* aDelegate) override;
|
||||||
|
@ -119,7 +116,8 @@ public:
|
||||||
NS_DECL_NSITHREADOBSERVER
|
NS_DECL_NSITHREADOBSERVER
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MessagePumpForNonMainUIThreads(nsIThread* aThread) :
|
MessagePumpForNonMainUIThreads() :
|
||||||
|
mThread(nullptr),
|
||||||
mInWait(false),
|
mInWait(false),
|
||||||
mWaitLock("mInWait")
|
mWaitLock("mInWait")
|
||||||
{
|
{
|
||||||
|
@ -129,6 +127,8 @@ public:
|
||||||
virtual void DoRunLoop() override;
|
virtual void DoRunLoop() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
nsIThread* mThread;
|
||||||
|
|
||||||
void SetInWait() {
|
void SetInWait() {
|
||||||
MutexAutoLock lock(mWaitLock);
|
MutexAutoLock lock(mWaitLock);
|
||||||
mInWait = true;
|
mInWait = true;
|
||||||
|
|
|
@ -390,7 +390,7 @@ nsThread::ThreadFunc(void* aArg)
|
||||||
{
|
{
|
||||||
// Scope for MessageLoop.
|
// Scope for MessageLoop.
|
||||||
nsAutoPtr<MessageLoop> loop(
|
nsAutoPtr<MessageLoop> loop(
|
||||||
new MessageLoop(MessageLoop::TYPE_MOZILLA_NONMAINTHREAD, self));
|
new MessageLoop(MessageLoop::TYPE_MOZILLA_NONMAINTHREAD));
|
||||||
|
|
||||||
// Now, process incoming events...
|
// Now, process incoming events...
|
||||||
loop->Run();
|
loop->Run();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче