forked from mirrors/gecko-dev
Backed out changeset 42315c023471 (bug 1799222) for causing multiple failures CLOSED TREE
This commit is contained in:
parent
7b23072da6
commit
77f27d96b0
21 changed files with 49 additions and 92 deletions
|
|
@ -17,7 +17,7 @@ namespace mozilla {
|
||||||
nsCOMPtr<nsIThread> mThread;
|
nsCOMPtr<nsIThread> mThread;
|
||||||
nsresult rv =
|
nsresult rv =
|
||||||
NS_NewNamedThread("DDMediaLogs", getter_AddRefs(mThread), nullptr,
|
NS_NewNamedThread("DDMediaLogs", getter_AddRefs(mThread), nullptr,
|
||||||
{.stackSize = nsIThreadManager::kThreadPoolStackSize});
|
nsIThreadManager::kThreadPoolStackSize);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return {rv, nullptr};
|
return {rv, nullptr};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class WorkerThread::Observer final : public nsIThreadObserver {
|
||||||
WorkerThread::WorkerThread(ConstructorKey)
|
WorkerThread::WorkerThread(ConstructorKey)
|
||||||
: nsThread(
|
: nsThread(
|
||||||
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
|
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
|
||||||
nsThread::NOT_MAIN_THREAD, {.stackSize = kWorkerStackSize}),
|
nsThread::NOT_MAIN_THREAD, kWorkerStackSize),
|
||||||
mLock("WorkerThread::mLock"),
|
mLock("WorkerThread::mLock"),
|
||||||
mWorkerPrivateCondVar(mLock, "WorkerThread::mWorkerPrivateCondVar"),
|
mWorkerPrivateCondVar(mLock, "WorkerThread::mWorkerPrivateCondVar"),
|
||||||
mWorkerPrivate(nullptr),
|
mWorkerPrivate(nullptr),
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ class WorkletThread::TerminateRunnable final : public Runnable {
|
||||||
WorkletThread::WorkletThread(WorkletImpl* aWorkletImpl)
|
WorkletThread::WorkletThread(WorkletImpl* aWorkletImpl)
|
||||||
: nsThread(
|
: nsThread(
|
||||||
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
|
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
|
||||||
nsThread::NOT_MAIN_THREAD, {.stackSize = kWorkletStackSize}),
|
nsThread::NOT_MAIN_THREAD, kWorkletStackSize),
|
||||||
mWorkletImpl(aWorkletImpl),
|
mWorkletImpl(aWorkletImpl),
|
||||||
mExitLoop(false),
|
mExitLoop(false),
|
||||||
mIsTerminating(false) {
|
mIsTerminating(false) {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ void CanvasRenderThread::Start() {
|
||||||
nsthread->SetUseHangMonitor(true);
|
nsthread->SetUseHangMonitor(true);
|
||||||
nsthread->SetPriority(nsISupportsPriority::PRIORITY_HIGH);
|
nsthread->SetPriority(nsISupportsPriority::PRIORITY_HIGH);
|
||||||
}),
|
}),
|
||||||
{.stackSize = stackSize});
|
stackSize);
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ CompositorThreadHolder::CreateCompositorThread() {
|
||||||
nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
|
nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
|
||||||
static_cast<nsThread*>(thread.get())->SetUseHangMonitor(true);
|
static_cast<nsThread*>(thread.get())->SetUseHangMonitor(true);
|
||||||
}),
|
}),
|
||||||
{.stackSize = stackSize});
|
stackSize);
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -788,7 +788,7 @@ nsSocketTransportService::Init() {
|
||||||
if (!XRE_IsContentProcess() ||
|
if (!XRE_IsContentProcess() ||
|
||||||
StaticPrefs::network_allow_raw_sockets_in_content_processes_AtStartup()) {
|
StaticPrefs::network_allow_raw_sockets_in_content_processes_AtStartup()) {
|
||||||
nsresult rv = NS_NewNamedThread("Socket Thread", getter_AddRefs(thread),
|
nsresult rv = NS_NewNamedThread("Socket Thread", getter_AddRefs(thread),
|
||||||
this, {.stackSize = GetThreadStackSize()});
|
this, GetThreadStackSize());
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
} else {
|
} else {
|
||||||
// In the child process, we just want a regular nsThread with no socket
|
// In the child process, we just want a regular nsThread with no socket
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ NS_IMETHODIMP nsWifiMonitor::StartWatching(nsIWifiListener* aListener) {
|
||||||
|
|
||||||
if (!mThread) {
|
if (!mThread) {
|
||||||
rv = NS_NewNamedThread("Wifi Monitor", getter_AddRefs(mThread), this,
|
rv = NS_NewNamedThread("Wifi Monitor", getter_AddRefs(mThread), this,
|
||||||
{.stackSize = GetMonitorThreadStackSize()});
|
GetMonitorThreadStackSize());
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class AndroidUiThread : public nsThread {
|
||||||
AndroidUiThread()
|
AndroidUiThread()
|
||||||
: nsThread(
|
: nsThread(
|
||||||
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
|
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
|
||||||
nsThread::NOT_MAIN_THREAD, {.stackSize = 0}) {}
|
nsThread::NOT_MAIN_THREAD, 0) {}
|
||||||
|
|
||||||
nsresult Dispatch(already_AddRefed<nsIRunnable> aEvent,
|
nsresult Dispatch(already_AddRefed<nsIRunnable> aEvent,
|
||||||
uint32_t aFlags) override;
|
uint32_t aFlags) override;
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ already_AddRefed<nsISerialEventTarget> ThreadEventQueue::PushEventQueue() {
|
||||||
auto queue = MakeUnique<EventQueue>();
|
auto queue = MakeUnique<EventQueue>();
|
||||||
RefPtr<NestedSink> sink = new NestedSink(queue.get(), this);
|
RefPtr<NestedSink> sink = new NestedSink(queue.get(), this);
|
||||||
RefPtr<ThreadEventTarget> eventTarget =
|
RefPtr<ThreadEventTarget> eventTarget =
|
||||||
new ThreadEventTarget(sink, NS_IsMainThread(), false);
|
new ThreadEventTarget(sink, NS_IsMainThread());
|
||||||
|
|
||||||
MutexAutoLock lock(mLock);
|
MutexAutoLock lock(mLock);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,13 @@ static mozilla::Atomic<bool, mozilla::SequentiallyConsistent>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ThreadEventTarget::ThreadEventTarget(ThreadTargetSink* aSink,
|
ThreadEventTarget::ThreadEventTarget(ThreadTargetSink* aSink,
|
||||||
bool aIsMainThread, bool aBlockDispatch)
|
bool aIsMainThread)
|
||||||
: mSink(aSink),
|
: mSink(aSink)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mIsMainThread(aIsMainThread),
|
,
|
||||||
|
mIsMainThread(aIsMainThread)
|
||||||
#endif
|
#endif
|
||||||
mBlockDispatch(aBlockDispatch) {
|
{
|
||||||
mThread = PR_GetCurrentThread();
|
mThread = PR_GetCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,14 +77,6 @@ ThreadEventTarget::Dispatch(already_AddRefed<nsIRunnable> aEvent,
|
||||||
PR_GetCurrentThread() == mThread,
|
PR_GetCurrentThread() == mThread,
|
||||||
"Dispatch to non-main thread after xpcom-shutdown-threads");
|
"Dispatch to non-main thread after xpcom-shutdown-threads");
|
||||||
|
|
||||||
if (mBlockDispatch && !(aFlags & NS_DISPATCH_IGNORE_BLOCK_DISPATCH)) {
|
|
||||||
MOZ_DIAGNOSTIC_ASSERT(
|
|
||||||
false,
|
|
||||||
"Attempt to dispatch to thread which does not usually process "
|
|
||||||
"dispatched runnables until shutdown");
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogRunnable::LogDispatch(event.get());
|
LogRunnable::LogDispatch(event.get());
|
||||||
|
|
||||||
if (aFlags & DISPATCH_SYNC) {
|
if (aFlags & DISPATCH_SYNC) {
|
||||||
|
|
@ -116,8 +109,7 @@ ThreadEventTarget::Dispatch(already_AddRefed<nsIRunnable> aEvent,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ASSERTION((aFlags & (NS_DISPATCH_AT_END |
|
NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL || aFlags == NS_DISPATCH_AT_END,
|
||||||
NS_DISPATCH_IGNORE_BLOCK_DISPATCH)) == aFlags,
|
|
||||||
"unexpected dispatch flags");
|
"unexpected dispatch flags");
|
||||||
if (!mSink->PutEvent(event.take(), EventQueuePriority::Normal)) {
|
if (!mSink->PutEvent(event.take(), EventQueuePriority::Normal)) {
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ class DelayedRunnable;
|
||||||
// be used with any ThreadTargetSink implementation.
|
// be used with any ThreadTargetSink implementation.
|
||||||
class ThreadEventTarget final : public nsISerialEventTarget {
|
class ThreadEventTarget final : public nsISerialEventTarget {
|
||||||
public:
|
public:
|
||||||
ThreadEventTarget(ThreadTargetSink* aSink, bool aIsMainThread,
|
ThreadEventTarget(ThreadTargetSink* aSink, bool aIsMainThread);
|
||||||
bool aBlockDispatch);
|
|
||||||
|
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
NS_DECL_NSIEVENTTARGET_FULL
|
NS_DECL_NSIEVENTTARGET_FULL
|
||||||
|
|
@ -53,9 +52,8 @@ class ThreadEventTarget final : public nsISerialEventTarget {
|
||||||
|
|
||||||
RefPtr<ThreadTargetSink> mSink;
|
RefPtr<ThreadTargetSink> mSink;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
const bool mIsMainThread;
|
bool mIsMainThread;
|
||||||
#endif
|
#endif
|
||||||
const bool mBlockDispatch;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
// Uncomment the following line to enable runtime stats during development.
|
// Uncomment the following line to enable runtime stats during development.
|
||||||
// #define TIMERS_RUNTIME_STATS
|
//#define TIMERS_RUNTIME_STATS
|
||||||
|
|
||||||
#ifdef TIMERS_RUNTIME_STATS
|
#ifdef TIMERS_RUNTIME_STATS
|
||||||
// This class gathers durations and displays some basic stats when destroyed.
|
// This class gathers durations and displays some basic stats when destroyed.
|
||||||
|
|
@ -376,8 +376,7 @@ nsresult TimerThread::Init() {
|
||||||
nsTimerEvent::Init();
|
nsTimerEvent::Init();
|
||||||
|
|
||||||
// We hold on to mThread to keep the thread alive.
|
// We hold on to mThread to keep the thread alive.
|
||||||
nsresult rv = NS_NewNamedThread("Timer", getter_AddRefs(mThread), this,
|
nsresult rv = NS_NewNamedThread("Timer", getter_AddRefs(mThread), this);
|
||||||
{.blockDispatch = true});
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
mThread = nullptr;
|
mThread = nullptr;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -65,15 +65,6 @@ interface nsIEventTarget : nsISupports
|
||||||
*/
|
*/
|
||||||
const unsigned long DISPATCH_EVENT_MAY_BLOCK = 4;
|
const unsigned long DISPATCH_EVENT_MAY_BLOCK = 4;
|
||||||
|
|
||||||
/**
|
|
||||||
* This flag specifies that the dispatched event should be delivered to the
|
|
||||||
* target thread even if the thread has been configured to block dispatching
|
|
||||||
* of runnables. This is generally done for threads which have their own
|
|
||||||
* internal event loop, such as thread pools or the timer thread, and will not
|
|
||||||
* service runnables dispatched to them until shutdown.
|
|
||||||
*/
|
|
||||||
const unsigned long DISPATCH_IGNORE_BLOCK_DISPATCH = 8;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IsOnCurrentThread() should return true if events dispatched to this target
|
* IsOnCurrentThread() should return true if events dispatched to this target
|
||||||
* can possibly run on the current thread, and false otherwise. In the case
|
* can possibly run on the current thread, and false otherwise. In the case
|
||||||
|
|
@ -225,7 +216,6 @@ public:
|
||||||
#define NS_DISPATCH_SYNC nsIEventTarget::DISPATCH_SYNC
|
#define NS_DISPATCH_SYNC nsIEventTarget::DISPATCH_SYNC
|
||||||
#define NS_DISPATCH_AT_END nsIEventTarget::DISPATCH_AT_END
|
#define NS_DISPATCH_AT_END nsIEventTarget::DISPATCH_AT_END
|
||||||
#define NS_DISPATCH_EVENT_MAY_BLOCK nsIEventTarget::DISPATCH_EVENT_MAY_BLOCK
|
#define NS_DISPATCH_EVENT_MAY_BLOCK nsIEventTarget::DISPATCH_EVENT_MAY_BLOCK
|
||||||
#define NS_DISPATCH_IGNORE_BLOCK_DISPATCH nsIEventTarget::DISPATCH_IGNORE_BLOCK_DISPATCH
|
|
||||||
|
|
||||||
// Convenient NS_DECL variant that includes some C++-only methods.
|
// Convenient NS_DECL variant that includes some C++-only methods.
|
||||||
#define NS_DECL_NSIEVENTTARGET_FULL \
|
#define NS_DECL_NSIEVENTTARGET_FULL \
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
[ptr] native PRThread(PRThread);
|
[ptr] native PRThread(PRThread);
|
||||||
native ThreadCreationOptions(nsIThreadManager::ThreadCreationOptions);
|
|
||||||
|
|
||||||
interface nsIEventTarget;
|
interface nsIEventTarget;
|
||||||
interface nsIRunnable;
|
interface nsIRunnable;
|
||||||
|
|
@ -54,21 +53,6 @@ interface nsIThreadManager : nsISupports
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const uint32_t kThreadPoolStackSize = DEFAULT_STACK_SIZE;
|
static const uint32_t kThreadPoolStackSize = DEFAULT_STACK_SIZE;
|
||||||
|
|
||||||
struct ThreadCreationOptions {
|
|
||||||
// The size in bytes to reserve for the thread's stack. A value of `0` means
|
|
||||||
// to use the platform default.
|
|
||||||
uint32_t stackSize = nsIThreadManager::DEFAULT_STACK_SIZE;
|
|
||||||
|
|
||||||
// If set to `true`, any attempts to dispatch runnables to this thread
|
|
||||||
// without `DISPATCH_IGNORE_BLOCK_DISPATCH` will fail.
|
|
||||||
//
|
|
||||||
// This is intended to be used for threads which are expected to generally
|
|
||||||
// only service a single runnable (other than thread lifecycle runnables),
|
|
||||||
// and perform their own event dispatching internaly, such as thread pool
|
|
||||||
// threads or the timer thread.
|
|
||||||
bool blockDispatch = false;
|
|
||||||
};
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,13 +60,14 @@ interface nsIThreadManager : nsISupports
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The name of the thread. If it is empty the thread will not be named.
|
* The name of the thread. If it is empty the thread will not be named.
|
||||||
* @param options
|
* @param stackSize
|
||||||
* Configuration options for the newly created thread.
|
* Number of bytes to reserve for the thread's stack. 0 means use platform
|
||||||
|
* default.
|
||||||
*
|
*
|
||||||
* @returns
|
* @returns
|
||||||
* The newly created nsIThread object.
|
* The newly created nsIThread object.
|
||||||
*/
|
*/
|
||||||
[noscript] nsIThread newNamedThread(in ACString name, in ThreadCreationOptions options);
|
[noscript] nsIThread newNamedThread(in ACString name, [optional] in unsigned long stackSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the main thread.
|
* Get the main thread.
|
||||||
|
|
|
||||||
|
|
@ -544,16 +544,15 @@ int sCanaryOutputFD = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsThread::nsThread(NotNull<SynchronizedEventQueue*> aQueue,
|
nsThread::nsThread(NotNull<SynchronizedEventQueue*> aQueue,
|
||||||
MainThreadFlag aMainThread,
|
MainThreadFlag aMainThread, uint32_t aStackSize)
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions)
|
|
||||||
: mEvents(aQueue.get()),
|
: mEvents(aQueue.get()),
|
||||||
mEventTarget(new ThreadEventTarget(
|
mEventTarget(
|
||||||
mEvents.get(), aMainThread == MAIN_THREAD, aOptions.blockDispatch)),
|
new ThreadEventTarget(mEvents.get(), aMainThread == MAIN_THREAD)),
|
||||||
mOutstandingShutdownContexts(0),
|
mOutstandingShutdownContexts(0),
|
||||||
mShutdownContext(nullptr),
|
mShutdownContext(nullptr),
|
||||||
mScriptObserver(nullptr),
|
mScriptObserver(nullptr),
|
||||||
mThreadName("<uninitialized>"),
|
mThreadName("<uninitialized>"),
|
||||||
mStackSize(aOptions.stackSize),
|
mStackSize(aStackSize),
|
||||||
mNestedEventLoopDepth(0),
|
mNestedEventLoopDepth(0),
|
||||||
mShutdownRequired(false),
|
mShutdownRequired(false),
|
||||||
mPriority(PRIORITY_NORMAL),
|
mPriority(PRIORITY_NORMAL),
|
||||||
|
|
|
||||||
|
|
@ -171,8 +171,7 @@ class nsThread : public nsIThreadInternal,
|
||||||
enum MainThreadFlag { MAIN_THREAD, NOT_MAIN_THREAD };
|
enum MainThreadFlag { MAIN_THREAD, NOT_MAIN_THREAD };
|
||||||
|
|
||||||
nsThread(NotNull<mozilla::SynchronizedEventQueue*> aQueue,
|
nsThread(NotNull<mozilla::SynchronizedEventQueue*> aQueue,
|
||||||
MainThreadFlag aMainThread,
|
MainThreadFlag aMainThread, uint32_t aStackSize);
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsThread();
|
nsThread();
|
||||||
|
|
|
||||||
|
|
@ -298,8 +298,8 @@ nsresult nsThreadManager::Init() {
|
||||||
RefPtr<ThreadEventQueue> synchronizedQueue =
|
RefPtr<ThreadEventQueue> synchronizedQueue =
|
||||||
new ThreadEventQueue(std::move(queue), true);
|
new ThreadEventQueue(std::move(queue), true);
|
||||||
|
|
||||||
mMainThread = new nsThread(WrapNotNull(synchronizedQueue),
|
mMainThread =
|
||||||
nsThread::MAIN_THREAD, {.stackSize = 0});
|
new nsThread(WrapNotNull(synchronizedQueue), nsThread::MAIN_THREAD, 0);
|
||||||
|
|
||||||
nsresult rv = mMainThread->InitCurrentThread();
|
nsresult rv = mMainThread->InitCurrentThread();
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
|
@ -452,8 +452,7 @@ nsThread* nsThreadManager::CreateCurrentThread(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<nsThread> thread =
|
RefPtr<nsThread> thread = new nsThread(WrapNotNull(aQueue), aMainThread, 0);
|
||||||
new nsThread(WrapNotNull(aQueue), aMainThread, {.stackSize = 0});
|
|
||||||
if (!thread || NS_FAILED(thread->InitCurrentThread())) {
|
if (!thread || NS_FAILED(thread->InitCurrentThread())) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -515,9 +514,8 @@ bool nsThreadManager::IsNSThread() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsThreadManager::NewNamedThread(
|
nsThreadManager::NewNamedThread(const nsACString& aName, uint32_t aStackSize,
|
||||||
const nsACString& aName, nsIThreadManager::ThreadCreationOptions aOptions,
|
nsIThread** aResult) {
|
||||||
nsIThread** aResult) {
|
|
||||||
// Note: can be called from arbitrary threads
|
// Note: can be called from arbitrary threads
|
||||||
|
|
||||||
// No new threads during Shutdown
|
// No new threads during Shutdown
|
||||||
|
|
@ -530,7 +528,7 @@ nsThreadManager::NewNamedThread(
|
||||||
RefPtr<ThreadEventQueue> queue =
|
RefPtr<ThreadEventQueue> queue =
|
||||||
new ThreadEventQueue(MakeUnique<EventQueue>());
|
new ThreadEventQueue(MakeUnique<EventQueue>());
|
||||||
RefPtr<nsThread> thr =
|
RefPtr<nsThread> thr =
|
||||||
new nsThread(WrapNotNull(queue), nsThread::NOT_MAIN_THREAD, aOptions);
|
new nsThread(WrapNotNull(queue), nsThread::NOT_MAIN_THREAD, aStackSize);
|
||||||
nsresult rv =
|
nsresult rv =
|
||||||
thr->Init(aName); // Note: blocks until the new thread has been set up
|
thr->Init(aName); // Note: blocks until the new thread has been set up
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,8 @@ nsresult nsThreadPool::PutEvent(already_AddRefed<nsIRunnable> aEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIThread> thread;
|
nsCOMPtr<nsIThread> thread;
|
||||||
nsresult rv = NS_NewNamedThread(
|
nsresult rv = NS_NewNamedThread(mThreadNaming.GetNextThreadName(name),
|
||||||
mThreadNaming.GetNextThreadName(name), getter_AddRefs(thread), nullptr,
|
getter_AddRefs(thread), nullptr, stackSize);
|
||||||
{.stackSize = stackSize, .blockDispatch = true});
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +146,7 @@ nsresult nsThreadPool::PutEvent(already_AddRefed<nsIRunnable> aEvent,
|
||||||
// asynchronously without worrying about anything.
|
// asynchronously without worrying about anything.
|
||||||
ShutdownThread(thread);
|
ShutdownThread(thread);
|
||||||
} else {
|
} else {
|
||||||
thread->Dispatch(this, NS_DISPATCH_IGNORE_BLOCK_DISPATCH);
|
thread->Dispatch(this, NS_DISPATCH_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class nsThreadSyncDispatch : public mozilla::Runnable {
|
||||||
mIsPending = false;
|
mIsPending = false;
|
||||||
|
|
||||||
// unblock the origin thread
|
// unblock the origin thread
|
||||||
mOrigin->Dispatch(this, NS_DISPATCH_IGNORE_BLOCK_DISPATCH);
|
mOrigin->Dispatch(this, NS_DISPATCH_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "mozilla/TimeStamp.h"
|
||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "nsExceptionHandler.h"
|
#include "nsExceptionHandler.h"
|
||||||
#include "nsIEventTarget.h"
|
|
||||||
#include "nsITimer.h"
|
#include "nsITimer.h"
|
||||||
#include "nsTimerImpl.h"
|
#include "nsTimerImpl.h"
|
||||||
#include "prsystem.h"
|
#include "prsystem.h"
|
||||||
|
|
@ -158,25 +157,24 @@ PrioritizableCancelableRunnable::GetPriority(uint32_t* aPriority) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
nsresult NS_NewNamedThread(const nsACString& aName, nsIThread** aResult,
|
nsresult NS_NewNamedThread(const nsACString& aName, nsIThread** aResult,
|
||||||
nsIRunnable* aInitialEvent,
|
nsIRunnable* aInitialEvent, uint32_t aStackSize) {
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions) {
|
|
||||||
nsCOMPtr<nsIRunnable> event = aInitialEvent;
|
nsCOMPtr<nsIRunnable> event = aInitialEvent;
|
||||||
return NS_NewNamedThread(aName, aResult, event.forget(), aOptions);
|
return NS_NewNamedThread(aName, aResult, event.forget(), aStackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult NS_NewNamedThread(const nsACString& aName, nsIThread** aResult,
|
nsresult NS_NewNamedThread(const nsACString& aName, nsIThread** aResult,
|
||||||
already_AddRefed<nsIRunnable> aInitialEvent,
|
already_AddRefed<nsIRunnable> aInitialEvent,
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions) {
|
uint32_t aStackSize) {
|
||||||
nsCOMPtr<nsIRunnable> event = std::move(aInitialEvent);
|
nsCOMPtr<nsIRunnable> event = std::move(aInitialEvent);
|
||||||
nsCOMPtr<nsIThread> thread;
|
nsCOMPtr<nsIThread> thread;
|
||||||
nsresult rv = nsThreadManager::get().nsThreadManager::NewNamedThread(
|
nsresult rv = nsThreadManager::get().nsThreadManager::NewNamedThread(
|
||||||
aName, aOptions, getter_AddRefs(thread));
|
aName, aStackSize, getter_AddRefs(thread));
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
rv = thread->Dispatch(event.forget(), NS_DISPATCH_IGNORE_BLOCK_DISPATCH);
|
rv = thread->Dispatch(event.forget(), NS_DISPATCH_NORMAL);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,32 +58,32 @@ class nsIThread;
|
||||||
extern nsresult NS_NewNamedThread(
|
extern nsresult NS_NewNamedThread(
|
||||||
const nsACString& aName, nsIThread** aResult,
|
const nsACString& aName, nsIThread** aResult,
|
||||||
nsIRunnable* aInitialEvent = nullptr,
|
nsIRunnable* aInitialEvent = nullptr,
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions = {});
|
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
|
||||||
|
|
||||||
extern nsresult NS_NewNamedThread(
|
extern nsresult NS_NewNamedThread(
|
||||||
const nsACString& aName, nsIThread** aResult,
|
const nsACString& aName, nsIThread** aResult,
|
||||||
already_AddRefed<nsIRunnable> aInitialEvent,
|
already_AddRefed<nsIRunnable> aInitialEvent,
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions = {});
|
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
|
||||||
|
|
||||||
template <size_t LEN>
|
template <size_t LEN>
|
||||||
inline nsresult NS_NewNamedThread(
|
inline nsresult NS_NewNamedThread(
|
||||||
const char (&aName)[LEN], nsIThread** aResult,
|
const char (&aName)[LEN], nsIThread** aResult,
|
||||||
already_AddRefed<nsIRunnable> aInitialEvent,
|
already_AddRefed<nsIRunnable> aInitialEvent,
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions = {}) {
|
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE) {
|
||||||
static_assert(LEN <= 16, "Thread name must be no more than 16 characters");
|
static_assert(LEN <= 16, "Thread name must be no more than 16 characters");
|
||||||
return NS_NewNamedThread(nsDependentCString(aName, LEN - 1), aResult,
|
return NS_NewNamedThread(nsDependentCString(aName, LEN - 1), aResult,
|
||||||
std::move(aInitialEvent), aOptions);
|
std::move(aInitialEvent), aStackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t LEN>
|
template <size_t LEN>
|
||||||
inline nsresult NS_NewNamedThread(
|
inline nsresult NS_NewNamedThread(
|
||||||
const char (&aName)[LEN], nsIThread** aResult,
|
const char (&aName)[LEN], nsIThread** aResult,
|
||||||
nsIRunnable* aInitialEvent = nullptr,
|
nsIRunnable* aInitialEvent = nullptr,
|
||||||
nsIThreadManager::ThreadCreationOptions aOptions = {}) {
|
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE) {
|
||||||
nsCOMPtr<nsIRunnable> event = aInitialEvent;
|
nsCOMPtr<nsIRunnable> event = aInitialEvent;
|
||||||
static_assert(LEN <= 16, "Thread name must be no more than 16 characters");
|
static_assert(LEN <= 16, "Thread name must be no more than 16 characters");
|
||||||
return NS_NewNamedThread(nsDependentCString(aName, LEN - 1), aResult,
|
return NS_NewNamedThread(nsDependentCString(aName, LEN - 1), aResult,
|
||||||
event.forget(), aOptions);
|
event.forget(), aStackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue