Backed out changeset 42315c023471 (bug 1799222) for causing multiple failures CLOSED TREE

This commit is contained in:
Cristian Tuns 2022-12-06 16:35:58 -05:00
parent 7b23072da6
commit 77f27d96b0
21 changed files with 49 additions and 92 deletions

View file

@ -17,7 +17,7 @@ namespace mozilla {
nsCOMPtr<nsIThread> mThread;
nsresult rv =
NS_NewNamedThread("DDMediaLogs", getter_AddRefs(mThread), nullptr,
{.stackSize = nsIThreadManager::kThreadPoolStackSize});
nsIThreadManager::kThreadPoolStackSize);
if (NS_WARN_IF(NS_FAILED(rv))) {
return {rv, nullptr};
}

View file

@ -76,7 +76,7 @@ class WorkerThread::Observer final : public nsIThreadObserver {
WorkerThread::WorkerThread(ConstructorKey)
: nsThread(
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
nsThread::NOT_MAIN_THREAD, {.stackSize = kWorkerStackSize}),
nsThread::NOT_MAIN_THREAD, kWorkerStackSize),
mLock("WorkerThread::mLock"),
mWorkerPrivateCondVar(mLock, "WorkerThread::mWorkerPrivateCondVar"),
mWorkerPrivate(nullptr),

View file

@ -257,7 +257,7 @@ class WorkletThread::TerminateRunnable final : public Runnable {
WorkletThread::WorkletThread(WorkletImpl* aWorkletImpl)
: nsThread(
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
nsThread::NOT_MAIN_THREAD, {.stackSize = kWorkletStackSize}),
nsThread::NOT_MAIN_THREAD, kWorkletStackSize),
mWorkletImpl(aWorkletImpl),
mExitLoop(false),
mIsTerminating(false) {

View file

@ -69,7 +69,7 @@ void CanvasRenderThread::Start() {
nsthread->SetUseHangMonitor(true);
nsthread->SetPriority(nsISupportsPriority::PRIORITY_HIGH);
}),
{.stackSize = stackSize});
stackSize);
if (NS_FAILED(rv)) {
return;

View file

@ -83,7 +83,7 @@ CompositorThreadHolder::CreateCompositorThread() {
nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
static_cast<nsThread*>(thread.get())->SetUseHangMonitor(true);
}),
{.stackSize = stackSize});
stackSize);
if (NS_FAILED(rv)) {
return nullptr;

View file

@ -788,7 +788,7 @@ nsSocketTransportService::Init() {
if (!XRE_IsContentProcess() ||
StaticPrefs::network_allow_raw_sockets_in_content_processes_AtStartup()) {
nsresult rv = NS_NewNamedThread("Socket Thread", getter_AddRefs(thread),
this, {.stackSize = GetThreadStackSize()});
this, GetThreadStackSize());
NS_ENSURE_SUCCESS(rv, rv);
} else {
// In the child process, we just want a regular nsThread with no socket

View file

@ -93,7 +93,7 @@ NS_IMETHODIMP nsWifiMonitor::StartWatching(nsIWifiListener* aListener) {
if (!mThread) {
rv = NS_NewNamedThread("Wifi Monitor", getter_AddRefs(mThread), this,
{.stackSize = GetMonitorThreadStackSize()});
GetMonitorThreadStackSize());
if (NS_FAILED(rv)) {
return rv;
}

View file

@ -60,7 +60,7 @@ class AndroidUiThread : public nsThread {
AndroidUiThread()
: nsThread(
MakeNotNull<ThreadEventQueue*>(MakeUnique<mozilla::EventQueue>()),
nsThread::NOT_MAIN_THREAD, {.stackSize = 0}) {}
nsThread::NOT_MAIN_THREAD, 0) {}
nsresult Dispatch(already_AddRefed<nsIRunnable> aEvent,
uint32_t aFlags) override;

View file

@ -209,7 +209,7 @@ already_AddRefed<nsISerialEventTarget> ThreadEventQueue::PushEventQueue() {
auto queue = MakeUnique<EventQueue>();
RefPtr<NestedSink> sink = new NestedSink(queue.get(), this);
RefPtr<ThreadEventTarget> eventTarget =
new ThreadEventTarget(sink, NS_IsMainThread(), false);
new ThreadEventTarget(sink, NS_IsMainThread());
MutexAutoLock lock(mLock);

View file

@ -31,12 +31,13 @@ static mozilla::Atomic<bool, mozilla::SequentiallyConsistent>
#endif
ThreadEventTarget::ThreadEventTarget(ThreadTargetSink* aSink,
bool aIsMainThread, bool aBlockDispatch)
: mSink(aSink),
bool aIsMainThread)
: mSink(aSink)
#ifdef DEBUG
mIsMainThread(aIsMainThread),
,
mIsMainThread(aIsMainThread)
#endif
mBlockDispatch(aBlockDispatch) {
{
mThread = PR_GetCurrentThread();
}
@ -76,14 +77,6 @@ ThreadEventTarget::Dispatch(already_AddRefed<nsIRunnable> aEvent,
PR_GetCurrentThread() == mThread,
"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());
if (aFlags & DISPATCH_SYNC) {
@ -116,8 +109,7 @@ ThreadEventTarget::Dispatch(already_AddRefed<nsIRunnable> aEvent,
return NS_OK;
}
NS_ASSERTION((aFlags & (NS_DISPATCH_AT_END |
NS_DISPATCH_IGNORE_BLOCK_DISPATCH)) == aFlags,
NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL || aFlags == NS_DISPATCH_AT_END,
"unexpected dispatch flags");
if (!mSink->PutEvent(event.take(), EventQueuePriority::Normal)) {
return NS_ERROR_UNEXPECTED;

View file

@ -19,8 +19,7 @@ class DelayedRunnable;
// be used with any ThreadTargetSink implementation.
class ThreadEventTarget final : public nsISerialEventTarget {
public:
ThreadEventTarget(ThreadTargetSink* aSink, bool aIsMainThread,
bool aBlockDispatch);
ThreadEventTarget(ThreadTargetSink* aSink, bool aIsMainThread);
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIEVENTTARGET_FULL
@ -53,9 +52,8 @@ class ThreadEventTarget final : public nsISerialEventTarget {
RefPtr<ThreadTargetSink> mSink;
#ifdef DEBUG
const bool mIsMainThread;
bool mIsMainThread;
#endif
const bool mBlockDispatch;
};
} // namespace mozilla

View file

@ -25,7 +25,7 @@
using namespace mozilla;
// Uncomment the following line to enable runtime stats during development.
// #define TIMERS_RUNTIME_STATS
//#define TIMERS_RUNTIME_STATS
#ifdef TIMERS_RUNTIME_STATS
// This class gathers durations and displays some basic stats when destroyed.
@ -376,8 +376,7 @@ nsresult TimerThread::Init() {
nsTimerEvent::Init();
// We hold on to mThread to keep the thread alive.
nsresult rv = NS_NewNamedThread("Timer", getter_AddRefs(mThread), this,
{.blockDispatch = true});
nsresult rv = NS_NewNamedThread("Timer", getter_AddRefs(mThread), this);
if (NS_FAILED(rv)) {
mThread = nullptr;
} else {

View file

@ -65,15 +65,6 @@ interface nsIEventTarget : nsISupports
*/
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
* 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_AT_END nsIEventTarget::DISPATCH_AT_END
#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.
#define NS_DECL_NSIEVENTTARGET_FULL \

View file

@ -7,7 +7,6 @@
#include "nsISupports.idl"
[ptr] native PRThread(PRThread);
native ThreadCreationOptions(nsIThreadManager::ThreadCreationOptions);
interface nsIEventTarget;
interface nsIRunnable;
@ -54,21 +53,6 @@ interface nsIThreadManager : nsISupports
#endif
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
* The name of the thread. If it is empty the thread will not be named.
* @param options
* Configuration options for the newly created thread.
* @param stackSize
* Number of bytes to reserve for the thread's stack. 0 means use platform
* default.
*
* @returns
* 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.

View file

@ -544,16 +544,15 @@ int sCanaryOutputFD = -1;
#endif
nsThread::nsThread(NotNull<SynchronizedEventQueue*> aQueue,
MainThreadFlag aMainThread,
nsIThreadManager::ThreadCreationOptions aOptions)
MainThreadFlag aMainThread, uint32_t aStackSize)
: mEvents(aQueue.get()),
mEventTarget(new ThreadEventTarget(
mEvents.get(), aMainThread == MAIN_THREAD, aOptions.blockDispatch)),
mEventTarget(
new ThreadEventTarget(mEvents.get(), aMainThread == MAIN_THREAD)),
mOutstandingShutdownContexts(0),
mShutdownContext(nullptr),
mScriptObserver(nullptr),
mThreadName("<uninitialized>"),
mStackSize(aOptions.stackSize),
mStackSize(aStackSize),
mNestedEventLoopDepth(0),
mShutdownRequired(false),
mPriority(PRIORITY_NORMAL),

View file

@ -171,8 +171,7 @@ class nsThread : public nsIThreadInternal,
enum MainThreadFlag { MAIN_THREAD, NOT_MAIN_THREAD };
nsThread(NotNull<mozilla::SynchronizedEventQueue*> aQueue,
MainThreadFlag aMainThread,
nsIThreadManager::ThreadCreationOptions aOptions);
MainThreadFlag aMainThread, uint32_t aStackSize);
private:
nsThread();

View file

@ -298,8 +298,8 @@ nsresult nsThreadManager::Init() {
RefPtr<ThreadEventQueue> synchronizedQueue =
new ThreadEventQueue(std::move(queue), true);
mMainThread = new nsThread(WrapNotNull(synchronizedQueue),
nsThread::MAIN_THREAD, {.stackSize = 0});
mMainThread =
new nsThread(WrapNotNull(synchronizedQueue), nsThread::MAIN_THREAD, 0);
nsresult rv = mMainThread->InitCurrentThread();
if (NS_FAILED(rv)) {
@ -452,8 +452,7 @@ nsThread* nsThreadManager::CreateCurrentThread(
return nullptr;
}
RefPtr<nsThread> thread =
new nsThread(WrapNotNull(aQueue), aMainThread, {.stackSize = 0});
RefPtr<nsThread> thread = new nsThread(WrapNotNull(aQueue), aMainThread, 0);
if (!thread || NS_FAILED(thread->InitCurrentThread())) {
return nullptr;
}
@ -515,9 +514,8 @@ bool nsThreadManager::IsNSThread() const {
}
NS_IMETHODIMP
nsThreadManager::NewNamedThread(
const nsACString& aName, nsIThreadManager::ThreadCreationOptions aOptions,
nsIThread** aResult) {
nsThreadManager::NewNamedThread(const nsACString& aName, uint32_t aStackSize,
nsIThread** aResult) {
// Note: can be called from arbitrary threads
// No new threads during Shutdown
@ -530,7 +528,7 @@ nsThreadManager::NewNamedThread(
RefPtr<ThreadEventQueue> queue =
new ThreadEventQueue(MakeUnique<EventQueue>());
RefPtr<nsThread> thr =
new nsThread(WrapNotNull(queue), nsThread::NOT_MAIN_THREAD, aOptions);
new nsThread(WrapNotNull(queue), nsThread::NOT_MAIN_THREAD, aStackSize);
nsresult rv =
thr->Init(aName); // Note: blocks until the new thread has been set up
if (NS_FAILED(rv)) {

View file

@ -119,9 +119,8 @@ nsresult nsThreadPool::PutEvent(already_AddRefed<nsIRunnable> aEvent,
}
nsCOMPtr<nsIThread> thread;
nsresult rv = NS_NewNamedThread(
mThreadNaming.GetNextThreadName(name), getter_AddRefs(thread), nullptr,
{.stackSize = stackSize, .blockDispatch = true});
nsresult rv = NS_NewNamedThread(mThreadNaming.GetNextThreadName(name),
getter_AddRefs(thread), nullptr, stackSize);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_UNEXPECTED;
}
@ -147,7 +146,7 @@ nsresult nsThreadPool::PutEvent(already_AddRefed<nsIRunnable> aEvent,
// asynchronously without worrying about anything.
ShutdownThread(thread);
} else {
thread->Dispatch(this, NS_DISPATCH_IGNORE_BLOCK_DISPATCH);
thread->Dispatch(this, NS_DISPATCH_NORMAL);
}
return NS_OK;

View file

@ -43,7 +43,7 @@ class nsThreadSyncDispatch : public mozilla::Runnable {
mIsPending = false;
// unblock the origin thread
mOrigin->Dispatch(this, NS_DISPATCH_IGNORE_BLOCK_DISPATCH);
mOrigin->Dispatch(this, NS_DISPATCH_NORMAL);
}
return NS_OK;

View file

@ -13,7 +13,6 @@
#include "mozilla/TimeStamp.h"
#include "nsComponentManagerUtils.h"
#include "nsExceptionHandler.h"
#include "nsIEventTarget.h"
#include "nsITimer.h"
#include "nsTimerImpl.h"
#include "prsystem.h"
@ -158,25 +157,24 @@ PrioritizableCancelableRunnable::GetPriority(uint32_t* aPriority) {
//-----------------------------------------------------------------------------
nsresult NS_NewNamedThread(const nsACString& aName, nsIThread** aResult,
nsIRunnable* aInitialEvent,
nsIThreadManager::ThreadCreationOptions aOptions) {
nsIRunnable* aInitialEvent, uint32_t aStackSize) {
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,
already_AddRefed<nsIRunnable> aInitialEvent,
nsIThreadManager::ThreadCreationOptions aOptions) {
uint32_t aStackSize) {
nsCOMPtr<nsIRunnable> event = std::move(aInitialEvent);
nsCOMPtr<nsIThread> thread;
nsresult rv = nsThreadManager::get().nsThreadManager::NewNamedThread(
aName, aOptions, getter_AddRefs(thread));
aName, aStackSize, getter_AddRefs(thread));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
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))) {
return rv;
}

View file

@ -58,32 +58,32 @@ class nsIThread;
extern nsresult NS_NewNamedThread(
const nsACString& aName, nsIThread** aResult,
nsIRunnable* aInitialEvent = nullptr,
nsIThreadManager::ThreadCreationOptions aOptions = {});
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
extern nsresult NS_NewNamedThread(
const nsACString& aName, nsIThread** aResult,
already_AddRefed<nsIRunnable> aInitialEvent,
nsIThreadManager::ThreadCreationOptions aOptions = {});
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
template <size_t LEN>
inline nsresult NS_NewNamedThread(
const char (&aName)[LEN], nsIThread** aResult,
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");
return NS_NewNamedThread(nsDependentCString(aName, LEN - 1), aResult,
std::move(aInitialEvent), aOptions);
std::move(aInitialEvent), aStackSize);
}
template <size_t LEN>
inline nsresult NS_NewNamedThread(
const char (&aName)[LEN], nsIThread** aResult,
nsIRunnable* aInitialEvent = nullptr,
nsIThreadManager::ThreadCreationOptions aOptions = {}) {
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE) {
nsCOMPtr<nsIRunnable> event = aInitialEvent;
static_assert(LEN <= 16, "Thread name must be no more than 16 characters");
return NS_NewNamedThread(nsDependentCString(aName, LEN - 1), aResult,
event.forget(), aOptions);
event.forget(), aStackSize);
}
/**