summaryrefslogtreecommitdiff
path: root/xpcom
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2022-04-09 21:23:59 -0500
committerMatt A. Tobin <email@mattatobin.com>2022-04-09 21:23:59 -0500
commit4a097bddac3c013464775d592314f7a0e69eb929 (patch)
tree6054f8e4875e036ce9e976a19173ac6ccd1bde2e /xpcom
parent5596516098894201ac412eb8f8d0351d23a279cf (diff)
downloadaura-central-4a097bddac3c013464775d592314f7a0e69eb929.tar.gz
[XPCOM/SEC?] Clean up threads
Diffstat (limited to 'xpcom')
-rw-r--r--xpcom/threads/LazyIdleThread.cpp13
-rw-r--r--xpcom/threads/LazyIdleThread.h3
-rw-r--r--xpcom/threads/nsProcessCommon.cpp19
-rw-r--r--xpcom/threads/nsThreadPool.cpp21
4 files changed, 37 insertions, 19 deletions
diff --git a/xpcom/threads/LazyIdleThread.cpp b/xpcom/threads/LazyIdleThread.cpp
index d74f515e8..c5c7a5f19 100644
--- a/xpcom/threads/LazyIdleThread.cpp
+++ b/xpcom/threads/LazyIdleThread.cpp
@@ -137,10 +137,15 @@ LazyIdleThread::EnsureThread()
return NS_OK;
}
- MOZ_ASSERT(!mPendingEventCount, "Shouldn't have events yet!");
- MOZ_ASSERT(!mIdleNotificationCount, "Shouldn't have idle events yet!");
- MOZ_ASSERT(!mIdleTimer, "Should have killed this long ago!");
- MOZ_ASSERT(!mThreadIsShuttingDown, "Should have cleared that!");
+#ifdef DEBUG
+ { // Lock scope
+ MutexAutoLock lock(mMutex);
+ MOZ_ASSERT(!mPendingEventCount, "Shouldn't have events yet!");
+ MOZ_ASSERT(!mIdleNotificationCount, "Shouldn't have idle events yet!");
+ MOZ_ASSERT(!mIdleTimer, "Should have killed this long ago!");
+ MOZ_ASSERT(!mThreadIsShuttingDown, "Should have cleared that!");
+ }
+#endif
nsresult rv;
diff --git a/xpcom/threads/LazyIdleThread.h b/xpcom/threads/LazyIdleThread.h
index 460971c7a..9d437171a 100644
--- a/xpcom/threads/LazyIdleThread.h
+++ b/xpcom/threads/LazyIdleThread.h
@@ -152,9 +152,10 @@ private:
nsCOMPtr<nsIThread> mThread;
/**
- * Protected by mMutex. Created when mThread has no pending events and fired
+ * Created when mThread has no pending events and fired
* at mOwningThread. Any thread that dispatches to mThread will take ownership
* of the timer and fire a separate cancel event to the owning thread.
+ * Only accessed from the owning thread.
*/
nsCOMPtr<nsITimer> mIdleTimer;
diff --git a/xpcom/threads/nsProcessCommon.cpp b/xpcom/threads/nsProcessCommon.cpp
index e815ec9ea..7d490c595 100644
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -280,10 +280,13 @@ nsProcess::ProcessComplete()
}
const char* topic;
- if (mExitValue < 0) {
- topic = "process-failed";
- } else {
- topic = "process-finished";
+ { // Lock scope
+ MutexAutoLock lock(mLock);
+ if (mExitValue < 0) {
+ topic = "process-failed";
+ } else {
+ topic = "process-finished";
+ }
}
mPid = -1;
@@ -412,8 +415,11 @@ nsProcess::RunProcess(bool aBlocking, char** aMyArgv, nsIObserver* aObserver,
}
}
- mExitValue = -1;
- mPid = -1;
+ {
+ MutexAutoLock lock(mLock);
+ mExitValue = -1;
+ mPid = -1;
+ }
#if defined(PROCESSMODEL_WINAPI)
BOOL retVal;
@@ -477,6 +483,7 @@ nsProcess::RunProcess(bool aBlocking, char** aMyArgv, nsIObserver* aObserver,
mBlocking = aBlocking;
if (aBlocking) {
Monitor(this);
+ MutexAutoLock lock(mLock);
if (mExitValue < 0) {
return NS_ERROR_FILE_EXECUTION_FAILED;
}
diff --git a/xpcom/threads/nsThreadPool.cpp b/xpcom/threads/nsThreadPool.cpp
index ec8f32671..2d852809a 100644
--- a/xpcom/threads/nsThreadPool.cpp
+++ b/xpcom/threads/nsThreadPool.cpp
@@ -155,8 +155,6 @@ nsThreadPool::Run()
{
mThreadNaming.SetThreadPoolName(mName);
- LOG(("THRD-P(%p) enter %s\n", this, mName.BeginReading()));
-
nsCOMPtr<nsIThread> current;
nsThreadManager::get().GetCurrentThread(getter_AddRefs(current));
@@ -169,6 +167,7 @@ nsThreadPool::Run()
{
MutexAutoLock lock(mMutex);
listener = mListener;
+ LOG(("THRD-P(%p) enter %s\n", this, mName.BeginReading()));
}
if (listener) {
@@ -223,7 +222,12 @@ nsThreadPool::Run()
}
}
if (event) {
- LOG(("THRD-P(%p) %s running [%p]\n", this, mName.BeginReading(), event.get()));
+#ifdef DEBUG
+ {
+ MutexAutoLock lock(mMutex);
+ LOG(("THRD-P(%p) %s running [%p]\n", this, mName.BeginReading(), event.get()));
+ }
+#endif
event->Run();
}
} while (!exitThread);
@@ -335,6 +339,7 @@ nsThreadPool::Shutdown()
NS_IMETHODIMP
nsThreadPool::GetThreadLimit(uint32_t* aValue)
{
+ MutexAutoLock lock(mMutex);
*aValue = mThreadLimit;
return NS_OK;
}
@@ -358,6 +363,7 @@ nsThreadPool::SetThreadLimit(uint32_t aValue)
NS_IMETHODIMP
nsThreadPool::GetIdleThreadLimit(uint32_t* aValue)
{
+ MutexAutoLock lock(mMutex);
*aValue = mIdleThreadLimit;
return NS_OK;
}
@@ -382,6 +388,7 @@ nsThreadPool::SetIdleThreadLimit(uint32_t aValue)
NS_IMETHODIMP
nsThreadPool::GetIdleThreadTimeout(uint32_t* aValue)
{
+ MutexAutoLock lock(mMutex);
*aValue = mIdleThreadTimeout;
return NS_OK;
}
@@ -438,11 +445,9 @@ nsThreadPool::SetListener(nsIThreadPoolListener* aListener)
NS_IMETHODIMP
nsThreadPool::SetName(const nsACString& aName)
{
- {
- MutexAutoLock lock(mMutex);
- if (mThreads.Count()) {
- return NS_ERROR_NOT_AVAILABLE;
- }
+ MutexAutoLock lock(mMutex);
+ if (mThreads.Count()) {
+ return NS_ERROR_NOT_AVAILABLE;
}
mName = aName;