зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1510226 - Remove vestigial references to cooperative scheduling r=froydnj
GetCurrentPhysicalThread and GetCurrentVirtualThread are, in practice, identical, as the TLS override that GetCurrentVirtualThread depends on is never actually set. This simply removes that and renames some things/ deletes some comments. Differential Revision: https://phabricator.services.mozilla.com/D41247 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0f917d19bb
Коммит
65be2b22c1
|
@ -1083,11 +1083,11 @@ class CreateImageBitmapFromBlob final : public CancelableRunnable,
|
|||
mCropRect(aCropRect),
|
||||
mOriginalCropRect(aCropRect),
|
||||
mMainThreadEventTarget(aMainThreadEventTarget),
|
||||
mThread(GetCurrentVirtualThread()) {}
|
||||
mThread(PR_GetCurrentThread()) {}
|
||||
|
||||
virtual ~CreateImageBitmapFromBlob() {}
|
||||
|
||||
bool IsCurrentThread() const { return mThread == GetCurrentVirtualThread(); }
|
||||
bool IsCurrentThread() const { return mThread == PR_GetCurrentThread(); }
|
||||
|
||||
// Called on the owning thread.
|
||||
nsresult StartMimeTypeAndDecodeAndCropBlob();
|
||||
|
|
|
@ -5147,7 +5147,7 @@ struct ConnectionPool::DatabaseInfo final {
|
|||
|
||||
void AssertIsOnConnectionThread() const {
|
||||
MOZ_ASSERT(mDEBUGConnectionThread);
|
||||
MOZ_ASSERT(GetCurrentPhysicalThread() == mDEBUGConnectionThread);
|
||||
MOZ_ASSERT(PR_GetCurrentThread() == mDEBUGConnectionThread);
|
||||
}
|
||||
|
||||
uint64_t TotalTransactionCount() const {
|
||||
|
@ -10904,7 +10904,7 @@ nsresult ConnectionPool::GetOrCreateConnection(
|
|||
NS_ConvertUTF16toUTF8(aDatabase->FilePath()).get()));
|
||||
|
||||
#ifdef DEBUG
|
||||
dbInfo->mDEBUGConnectionThread = GetCurrentPhysicalThread();
|
||||
dbInfo->mDEBUGConnectionThread = PR_GetCurrentThread();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -4072,7 +4072,7 @@ void SourceListener::Activate(RefPtr<MediaDevice> aAudioDevice,
|
|||
MOZ_ASSERT(!mStopped, "Cannot activate stopped source listener");
|
||||
MOZ_ASSERT(!Activated(), "Already activated");
|
||||
|
||||
mMainThreadCheck = GetCurrentVirtualThread();
|
||||
mMainThreadCheck = PR_GetCurrentThread();
|
||||
if (aAudioDevice) {
|
||||
bool offWhileDisabled =
|
||||
aAudioDevice->GetMediaSource() == MediaSourceEnum::Microphone &&
|
||||
|
|
|
@ -829,7 +829,7 @@ bool MessageChannel::Open(Transport* aTransport, MessageLoop* aIOLoop,
|
|||
|
||||
mMonitor = new RefCountedMonitor();
|
||||
mWorkerLoop = MessageLoop::current();
|
||||
mWorkerThread = GetCurrentVirtualThread();
|
||||
mWorkerThread = PR_GetCurrentThread();
|
||||
mWorkerLoop->AddDestructionObserver(this);
|
||||
mListener->OnIPCChannelOpened();
|
||||
|
||||
|
@ -910,7 +910,7 @@ void MessageChannel::OnOpenAsSlave(MessageChannel* aTargetChan, Side aSide) {
|
|||
void MessageChannel::CommonThreadOpenInit(MessageChannel* aTargetChan,
|
||||
Side aSide) {
|
||||
mWorkerLoop = MessageLoop::current();
|
||||
mWorkerThread = GetCurrentVirtualThread();
|
||||
mWorkerThread = PR_GetCurrentThread();
|
||||
mWorkerLoop->AddDestructionObserver(this);
|
||||
mListener->OnIPCChannelOpened();
|
||||
|
||||
|
|
|
@ -544,7 +544,7 @@ class MessageChannel : HasResultCodes, MessageLoop::DestructionObserver {
|
|||
// Can be run on either thread
|
||||
void AssertWorkerThread() const {
|
||||
MOZ_ASSERT(mWorkerThread, "Channel hasn't been opened yet");
|
||||
MOZ_RELEASE_ASSERT(mWorkerThread == GetCurrentVirtualThread(),
|
||||
MOZ_RELEASE_ASSERT(mWorkerThread == PR_GetCurrentThread(),
|
||||
"not on worker thread!");
|
||||
}
|
||||
|
||||
|
@ -562,7 +562,7 @@ class MessageChannel : HasResultCodes, MessageLoop::DestructionObserver {
|
|||
// If we aren't a same-thread channel, our "link" thread is _not_ our
|
||||
// worker thread!
|
||||
MOZ_ASSERT(mWorkerThread, "Channel hasn't been opened yet");
|
||||
MOZ_RELEASE_ASSERT(mWorkerThread != GetCurrentVirtualThread(),
|
||||
MOZ_RELEASE_ASSERT(mWorkerThread != PR_GetCurrentThread(),
|
||||
"on worker thread but should not be!");
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ mozilla::dom::ContentParent* ProtocolFuzzerHelper::CreateContentParent(
|
|||
mozilla::dom::ContentParent* aOpener, const nsAString& aRemoteType) {
|
||||
auto* cp = new mozilla::dom::ContentParent(aOpener, aRemoteType);
|
||||
// TODO: this duplicates MessageChannel::Open
|
||||
cp->GetIPCChannel()->mWorkerThread = GetCurrentVirtualThread();
|
||||
cp->GetIPCChannel()->mWorkerThread = PR_GetCurrentThread();
|
||||
cp->GetIPCChannel()->mMonitor = new RefCountedMonitor();
|
||||
return cp;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ nsresult NS_FASTCALL NS_TableDrivenQI(void* aThis, REFNSIID aIID,
|
|||
}
|
||||
|
||||
#ifdef MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
|
||||
nsAutoOwningThread::nsAutoOwningThread() : mThread(GetCurrentVirtualThread()) {}
|
||||
nsAutoOwningThread::nsAutoOwningThread() : mThread(PR_GetCurrentThread()) {}
|
||||
|
||||
void nsAutoOwningThread::AssertCurrentThreadOwnsMe(const char* msg) const {
|
||||
if (MOZ_UNLIKELY(!IsCurrentThread())) {
|
||||
|
@ -42,6 +42,6 @@ void nsAutoOwningThread::AssertCurrentThreadOwnsMe(const char* msg) const {
|
|||
}
|
||||
|
||||
bool nsAutoOwningThread::IsCurrentThread() const {
|
||||
return mThread == GetCurrentVirtualThread();
|
||||
return mThread == PR_GetCurrentThread();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -164,7 +164,7 @@ bool TaskQueue::IsEmpty() {
|
|||
}
|
||||
|
||||
bool TaskQueue::IsCurrentThreadIn() const {
|
||||
bool in = mRunningThread == GetCurrentPhysicalThread();
|
||||
bool in = mRunningThread == PR_GetCurrentThread();
|
||||
return in;
|
||||
}
|
||||
|
||||
|
|
|
@ -156,13 +156,13 @@ class TaskQueue : public AbstractThread {
|
|||
sCurrentThreadTLS.set(aQueue);
|
||||
|
||||
MOZ_ASSERT(mQueue->mRunningThread == nullptr);
|
||||
mQueue->mRunningThread = GetCurrentPhysicalThread();
|
||||
mQueue->mRunningThread = PR_GetCurrentThread();
|
||||
}
|
||||
|
||||
~AutoTaskGuard() {
|
||||
DrainDirectTasks();
|
||||
|
||||
MOZ_ASSERT(mQueue->mRunningThread == GetCurrentPhysicalThread());
|
||||
MOZ_ASSERT(mQueue->mRunningThread == PR_GetCurrentThread());
|
||||
mQueue->mRunningThread = nullptr;
|
||||
|
||||
sCurrentThreadTLS.set(mLastCurrentThread);
|
||||
|
|
|
@ -89,12 +89,10 @@ NS_IMPL_ISUPPORTS_INHERITED(DelayedRunnable, Runnable, nsITimerCallback)
|
|||
ThreadEventTarget::ThreadEventTarget(ThreadTargetSink* aSink,
|
||||
bool aIsMainThread)
|
||||
: mSink(aSink), mIsMainThread(aIsMainThread) {
|
||||
mVirtualThread = GetCurrentVirtualThread();
|
||||
mThread = PR_GetCurrentThread();
|
||||
}
|
||||
|
||||
void ThreadEventTarget::SetCurrentThread() {
|
||||
mVirtualThread = GetCurrentVirtualThread();
|
||||
}
|
||||
void ThreadEventTarget::SetCurrentThread() { mThread = PR_GetCurrentThread(); }
|
||||
|
||||
NS_IMPL_ISUPPORTS(ThreadEventTarget, nsIEventTarget, nsISerialEventTarget)
|
||||
|
||||
|
@ -185,6 +183,6 @@ ThreadEventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread) {
|
|||
|
||||
NS_IMETHODIMP_(bool)
|
||||
ThreadEventTarget::IsOnCurrentThreadInfallible() {
|
||||
// Rely on mVirtualThread being correct.
|
||||
// Rely on mThread being correct.
|
||||
MOZ_CRASH("IsOnCurrentThreadInfallible should never be called on nsIThread");
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ interface nsIEventTarget : nsISupports
|
|||
*
|
||||
* The infallible version of IsOnCurrentThread() is optimized to avoid a
|
||||
* virtual call for non-thread event targets. Thread targets should set
|
||||
* mVirtualThread to their virtual PRThread. Non-thread targets should leave
|
||||
* mVirtualThread null and implement IsOnCurrentThreadInfallible() to
|
||||
* mThread to their virtual PRThread. Non-thread targets should leave
|
||||
* mThread null and implement IsOnCurrentThreadInfallible() to
|
||||
* return the correct answer.
|
||||
*
|
||||
* The fallible version of IsOnCurrentThread may return errors, such as during
|
||||
|
@ -81,13 +81,13 @@ interface nsIEventTarget : nsISupports
|
|||
%{C++
|
||||
public:
|
||||
// Infallible. Defined in nsThreadUtils.cpp. Delegates to
|
||||
// IsOnCurrentThreadInfallible when mVirtualThread is null.
|
||||
// IsOnCurrentThreadInfallible when mThread is null.
|
||||
bool IsOnCurrentThread();
|
||||
|
||||
protected:
|
||||
PRThread* mVirtualThread;
|
||||
PRThread* mThread;
|
||||
|
||||
nsIEventTarget() : mVirtualThread(nullptr) {}
|
||||
nsIEventTarget() : mThread(nullptr) {}
|
||||
%}
|
||||
// Note that this method is protected. We define it through IDL, rather than
|
||||
// in a %{C++ block, to ensure that the correct method indices are recorded
|
||||
|
|
|
@ -418,7 +418,6 @@ void nsThread::ThreadFunc(void* aArg) {
|
|||
MOZ_ASSERT(self->mEvents);
|
||||
|
||||
self->mThread = PR_GetCurrentThread();
|
||||
self->mVirtualThread = GetCurrentVirtualThread();
|
||||
self->mEventTarget->SetCurrentThread();
|
||||
SetupCurrentThreadForChaosMode();
|
||||
|
||||
|
@ -594,7 +593,6 @@ nsThread::nsThread(NotNull<SynchronizedEventQueue*> aQueue,
|
|||
new ThreadEventTarget(mEvents.get(), aMainThread == MAIN_THREAD)),
|
||||
mShutdownContext(nullptr),
|
||||
mScriptObserver(nullptr),
|
||||
mThread(nullptr),
|
||||
mStackSize(aStackSize),
|
||||
mNestedEventLoopDepth(0),
|
||||
mCurrentEventLoopDepth(MaxValue<uint32_t>::value),
|
||||
|
@ -617,7 +615,6 @@ nsThread::nsThread()
|
|||
mEventTarget(nullptr),
|
||||
mShutdownContext(nullptr),
|
||||
mScriptObserver(nullptr),
|
||||
mThread(nullptr),
|
||||
mStackSize(0),
|
||||
mNestedEventLoopDepth(0),
|
||||
mCurrentEventLoopDepth(MaxValue<uint32_t>::value),
|
||||
|
@ -692,7 +689,6 @@ nsresult nsThread::Init(const nsACString& aName) {
|
|||
|
||||
nsresult nsThread::InitCurrentThread() {
|
||||
mThread = PR_GetCurrentThread();
|
||||
mVirtualThread = GetCurrentVirtualThread();
|
||||
SetupCurrentThreadForChaosMode();
|
||||
InitCommon();
|
||||
|
||||
|
@ -736,13 +732,13 @@ nsThread::IsOnCurrentThread(bool* aResult) {
|
|||
if (mEventTarget) {
|
||||
return mEventTarget->IsOnCurrentThread(aResult);
|
||||
}
|
||||
*aResult = GetCurrentVirtualThread() == mVirtualThread;
|
||||
*aResult = PR_GetCurrentThread() == mThread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
nsThread::IsOnCurrentThreadInfallible() {
|
||||
// Rely on mVirtualThread being correct.
|
||||
// Rely on mThread being correct.
|
||||
MOZ_CRASH("IsOnCurrentThreadInfallible should never be called on nsIThread");
|
||||
}
|
||||
|
||||
|
@ -859,7 +855,6 @@ void nsThread::ShutdownComplete(NotNull<nsThreadShutdownContext*> aContext) {
|
|||
// Now, it should be safe to join without fear of dead-locking.
|
||||
|
||||
PR_JoinThread(mThread);
|
||||
mThread = nullptr;
|
||||
|
||||
#ifdef DEBUG
|
||||
nsCOMPtr<nsIThreadObserver> obs = mEvents->GetObserver();
|
||||
|
|
|
@ -212,7 +212,6 @@ class nsThread : public nsIThreadInternal,
|
|||
|
||||
mozilla::CycleCollectedJSContext* mScriptObserver;
|
||||
|
||||
PRThread* mThread;
|
||||
void* mStackBase = nullptr;
|
||||
uint32_t mStackSize;
|
||||
uint32_t mThreadId;
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
using namespace mozilla;
|
||||
|
||||
static MOZ_THREAD_LOCAL(bool) sTLSIsMainThread;
|
||||
static MOZ_THREAD_LOCAL(PRThread*) gTlsCurrentVirtualThread;
|
||||
|
||||
bool NS_IsMainThreadTLSInitialized() { return sTLSIsMainThread.initialized(); }
|
||||
|
||||
|
@ -50,18 +49,6 @@ void NS_SetMainThread() {
|
|||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
||||
void NS_SetMainThread(PRThread* aVirtualThread) {
|
||||
MOZ_ASSERT(!gTlsCurrentVirtualThread.get());
|
||||
gTlsCurrentVirtualThread.set(aVirtualThread);
|
||||
NS_SetMainThread();
|
||||
}
|
||||
|
||||
void NS_UnsetMainThread() {
|
||||
sTLSIsMainThread.set(false);
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
gTlsCurrentVirtualThread.set(nullptr);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -202,10 +189,6 @@ nsresult nsThreadManager::Init() {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!gTlsCurrentVirtualThread.init()) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (PR_NewThreadPrivateIndex(&mCurThreadIndex, ReleaseThread) == PR_FAILURE) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -598,20 +581,3 @@ nsThreadManager::IdleDispatchToMainThread(nsIRunnable* aEvent,
|
|||
return NS_DispatchToThreadQueue(event.forget(), mMainThread,
|
||||
EventQueuePriority::Idle);
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
PRThread* GetCurrentVirtualThread() {
|
||||
// We call GetCurrentVirtualThread very early in startup, before the TLS is
|
||||
// initialized. Make sure we don't assert in that case.
|
||||
if (gTlsCurrentVirtualThread.initialized()) {
|
||||
if (gTlsCurrentVirtualThread.get()) {
|
||||
return gTlsCurrentVirtualThread.get();
|
||||
}
|
||||
}
|
||||
return PR_GetCurrentThread();
|
||||
}
|
||||
|
||||
PRThread* GetCurrentPhysicalThread() { return PR_GetCurrentThread(); }
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -601,8 +601,8 @@ size_t GetNumberOfProcessors() {
|
|||
} // namespace mozilla
|
||||
|
||||
bool nsIEventTarget::IsOnCurrentThread() {
|
||||
if (mVirtualThread) {
|
||||
return mVirtualThread == GetCurrentVirtualThread();
|
||||
if (mThread) {
|
||||
return mThread == PR_GetCurrentThread();
|
||||
}
|
||||
return IsOnCurrentThreadInfallible();
|
||||
}
|
||||
|
|
|
@ -1695,50 +1695,6 @@ extern mozilla::TimeStamp NS_GetTimerDeadlineHintOnCurrentThread(
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* Cooperative thread scheduling is governed by two rules:
|
||||
* - Only one thread in the pool of cooperatively scheduled threads runs at a
|
||||
* time.
|
||||
* - Thread switching happens at well-understood safe points.
|
||||
*
|
||||
* In some cases we may want to treat all the threads in a cooperative pool as a
|
||||
* single thread, while other parts of the code may want to view them as
|
||||
* separate threads. GetCurrentVirtualThread() will return the same value for
|
||||
* all threads in a cooperative thread pool. GetCurrentPhysicalThread will
|
||||
* return a different value for each thread in the pool.
|
||||
*
|
||||
* Thread safety assertions are a concrete example where GetCurrentVirtualThread
|
||||
* should be used. An object may want to assert that it only can be used on the
|
||||
* thread that created it. Such assertions would normally prevent the object
|
||||
* from being used on different cooperative threads. However, the object might
|
||||
* really only care that it's used atomically. Cooperative scheduling guarantees
|
||||
* that it will be (assuming we don't yield in the middle of modifying the
|
||||
* object). So we can weaken the assertion to compare the virtual thread the
|
||||
* object was created on to the virtual thread on which it's being used. This
|
||||
* assertion allows the object to be used across threads in a cooperative thread
|
||||
* pool while preventing accesses across preemptively scheduled threads (which
|
||||
* would be unsafe).
|
||||
*/
|
||||
|
||||
// Returns the PRThread on which this code is running.
|
||||
PRThread* GetCurrentPhysicalThread();
|
||||
|
||||
// Returns a "virtual" PRThread that should only be used for comparison with
|
||||
// other calls to GetCurrentVirtualThread. Two threads in the same cooperative
|
||||
// thread pool will return the same virtual thread. Threads that are not
|
||||
// cooperatively scheduled will have their own unique virtual PRThread (which
|
||||
// will be equal to their physical PRThread).
|
||||
//
|
||||
// The return value of GetCurrentVirtualThread() is guaranteed not to change
|
||||
// throughout the lifetime of a thread.
|
||||
//
|
||||
// Note that the original main thread (the first one created in the process) is
|
||||
// considered as part of the pool of cooperative threads, so the return value of
|
||||
// GetCurrentVirtualThread() for this thread (throughout its lifetime, even
|
||||
// during shutdown) is the same as the return value from any other thread in the
|
||||
// cooperative pool.
|
||||
PRThread* GetCurrentVirtualThread();
|
||||
|
||||
// These functions return event targets that can be used to dispatch to the
|
||||
// current or main thread. They can also be used to test if you're on those
|
||||
// threads (via IsOnCurrentThread). These functions should be used in preference
|
||||
|
|
Загрузка…
Ссылка в новой задаче