mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1776209 - RemoteLazyInputStreamThread: Replace gShutdownHasStarted with appropriate IsInOrBeyond check. r=dom-storage-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D156794
This commit is contained in:
parent
70537a9a48
commit
25dc1787a6
@ -7,6 +7,7 @@
|
||||
#include "RemoteLazyInputStreamThread.h"
|
||||
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/AppShutdown.h"
|
||||
#include "mozilla/SchedulerGroup.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
@ -23,7 +24,6 @@ namespace {
|
||||
|
||||
StaticMutex gRemoteLazyThreadMutex;
|
||||
StaticRefPtr<RemoteLazyInputStreamThread> gRemoteLazyThread;
|
||||
bool gShutdownHasStarted = false;
|
||||
|
||||
class ThreadInitializeRunnable final : public Runnable {
|
||||
public:
|
||||
@ -49,25 +49,31 @@ class ThreadInitializeRunnable final : public Runnable {
|
||||
|
||||
NS_IMPL_ISUPPORTS(RemoteLazyInputStreamThread, nsIObserver, nsIEventTarget)
|
||||
|
||||
bool RLISThreadIsInOrBeyondShutdown() {
|
||||
// ShutdownPhase::XPCOMShutdownThreads matches
|
||||
// obs->AddObserver(this, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID, false);
|
||||
return AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads);
|
||||
}
|
||||
|
||||
/* static */
|
||||
RemoteLazyInputStreamThread* RemoteLazyInputStreamThread::Get() {
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
|
||||
if (gShutdownHasStarted) {
|
||||
if (RLISThreadIsInOrBeyondShutdown()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
|
||||
return gRemoteLazyThread;
|
||||
}
|
||||
|
||||
/* static */
|
||||
RemoteLazyInputStreamThread* RemoteLazyInputStreamThread::GetOrCreate() {
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
|
||||
if (gShutdownHasStarted) {
|
||||
if (RLISThreadIsInOrBeyondShutdown()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
|
||||
if (!gRemoteLazyThread) {
|
||||
gRemoteLazyThread = new RemoteLazyInputStreamThread();
|
||||
if (!gRemoteLazyThread->Initialize()) {
|
||||
@ -122,7 +128,6 @@ RemoteLazyInputStreamThread::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
mThread = nullptr;
|
||||
}
|
||||
|
||||
gShutdownHasStarted = true;
|
||||
gRemoteLazyThread = nullptr;
|
||||
|
||||
return NS_OK;
|
||||
@ -143,14 +148,14 @@ RemoteLazyInputStreamThread::IsOnCurrentThread(bool* aRetval) {
|
||||
NS_IMETHODIMP
|
||||
RemoteLazyInputStreamThread::Dispatch(already_AddRefed<nsIRunnable> aRunnable,
|
||||
uint32_t aFlags) {
|
||||
if (RLISThreadIsInOrBeyondShutdown()) {
|
||||
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable(aRunnable);
|
||||
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
|
||||
if (gShutdownHasStarted) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
return mThread->Dispatch(runnable.forget(), aFlags);
|
||||
}
|
||||
|
||||
@ -178,9 +183,9 @@ RemoteLazyInputStreamThread::UnregisterShutdownTask(nsITargetShutdownTask*) {
|
||||
}
|
||||
|
||||
bool IsOnDOMFileThread() {
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
MOZ_ASSERT(!RLISThreadIsInOrBeyondShutdown());
|
||||
|
||||
MOZ_ASSERT(!gShutdownHasStarted);
|
||||
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
|
||||
MOZ_ASSERT(gRemoteLazyThread);
|
||||
|
||||
return gRemoteLazyThread->IsOnCurrentThreadInfallible();
|
||||
|
Loading…
Reference in New Issue
Block a user