Bug 1649729 - Get rid of MOZ_ACCESS_THREAD_BOUND macro. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D81843
This commit is contained in:
Simon Giesecke 2020-07-01 13:13:23 +00:00
Родитель dc25d4ae8f
Коммит 61e4a0be9b
6 изменённых файлов: 79 добавлений и 82 удалений

Просмотреть файл

@ -306,7 +306,7 @@ bool ServiceWorkerOp::MaybeStart(RemoteWorkerChild* aOwner,
MOZ_ASSERT(aOwner);
MOZ_ASSERT(aOwner->GetOwningEventTarget()->IsOnCurrentThread());
MOZ_ACCESS_THREAD_BOUND(aOwner->mLauncherData, launcherData);
auto launcherData = aOwner->mLauncherData.Access();
if (NS_WARN_IF(!launcherData->mIPCActive)) {
RejectAll(NS_ERROR_DOM_ABORT_ERR);

Просмотреть файл

@ -1368,7 +1368,7 @@ nsresult WorkerPrivate::SetCSPFromHeaderValues(
}
void WorkerPrivate::StoreCSPOnClient() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mScope);
if (mLoadInfo.mCSPInfo) {
data->mScope->GetClientSource()->SetCspInfo(*mLoadInfo.mCSPInfo);
@ -1917,7 +1917,7 @@ void WorkerPrivate::OfflineStatusChangeEvent(bool aIsOffline) {
}
void WorkerPrivate::OfflineStatusChangeEventInternal(bool aIsOffline) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
// The worker is already in this state. No need to dispatch an event.
if (data->mOnLine == !aIsOffline) {
@ -2828,7 +2828,7 @@ void WorkerPrivate::RunLoopNeverRan() {
}
void WorkerPrivate::DoRunLoop(JSContext* aCx) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(mThread);
MOZ_RELEASE_ASSERT(!GetExecutionManager());
@ -3115,7 +3115,7 @@ ClientType WorkerPrivate::GetClientType() const {
}
UniquePtr<ClientSource> WorkerPrivate::CreateClientSource() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(!data->mScope, "Client should be created before the global");
auto clientSource = ClientManager::CreateSource(
@ -3178,17 +3178,17 @@ void WorkerPrivate::EnsurePerformanceStorage() {
}
bool WorkerPrivate::GetExecutionGranted() const {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return data->mJSThreadExecutionGranted;
}
void WorkerPrivate::SetExecutionGranted(bool aGranted) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
data->mJSThreadExecutionGranted = aGranted;
}
void WorkerPrivate::ScheduleTimeSliceExpiration(uint32_t aDelay) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (!data->mTSTimer) {
data->mTSTimer = NS_NewTimer();
@ -3206,22 +3206,22 @@ void WorkerPrivate::ScheduleTimeSliceExpiration(uint32_t aDelay) {
}
void WorkerPrivate::CancelTimeSliceExpiration() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ALWAYS_SUCCEEDS(data->mTSTimer->Cancel());
}
JSExecutionManager* WorkerPrivate::GetExecutionManager() const {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return data->mExecutionManager.get();
}
void WorkerPrivate::SetExecutionManager(JSExecutionManager* aManager) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
data->mExecutionManager = aManager;
}
void WorkerPrivate::ExecutionReady() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
{
MutexAutoLock lock(mMutex);
if (mStatus >= Canceling) {
@ -3236,7 +3236,7 @@ void WorkerPrivate::ExecutionReady() {
}
void WorkerPrivate::InitializeGCTimers() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
// We need a timer for GC. The basic plan is to run a non-shrinking GC
// periodically (PERIODIC_GC_TIMER_DELAY_SEC) while the worker is running.
@ -3251,7 +3251,7 @@ void WorkerPrivate::InitializeGCTimers() {
}
void WorkerPrivate::SetGCTimerMode(GCTimerMode aMode) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mGCTimer);
if ((aMode == PeriodicTimer && data->mPeriodicGCTimerRunning) ||
@ -3305,7 +3305,7 @@ void WorkerPrivate::SetGCTimerMode(GCTimerMode aMode) {
}
void WorkerPrivate::ShutdownGCTimers() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mGCTimer);
@ -3320,7 +3320,7 @@ void WorkerPrivate::ShutdownGCTimers() {
}
bool WorkerPrivate::InterruptCallback(JSContext* aCx) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
AutoYieldJSThreadExecution yield;
@ -3407,7 +3407,7 @@ void WorkerPrivate::ScheduleDeletion(WorkerRanOrNot aRanOrNot) {
{
// mWorkerThreadAccessible's accessor must be destructed before
// the scheduled Runnable gets to run.
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mChildWorkers.IsEmpty());
}
MOZ_ASSERT(mSyncLoopStack.IsEmpty());
@ -3450,7 +3450,7 @@ bool WorkerPrivate::CollectRuntimeStats(JS::RuntimeStats* aRtStats,
}
void WorkerPrivate::EnableMemoryReporter() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(!data->mMemoryReporter);
// No need to lock here since the main thread can't race until we've
@ -3466,7 +3466,7 @@ void WorkerPrivate::EnableMemoryReporter() {
}
void WorkerPrivate::DisableMemoryReporter() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
RefPtr<MemoryReporter> memoryReporter;
{
@ -3589,7 +3589,7 @@ void WorkerPrivate::ClearDebuggerEventQueue() {
}
bool WorkerPrivate::FreezeInternal() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mScope);
NS_ASSERTION(!data->mFrozen, "Already frozen!");
@ -3610,7 +3610,7 @@ bool WorkerPrivate::FreezeInternal() {
}
bool WorkerPrivate::ThawInternal() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mScope);
NS_ASSERTION(data->mFrozen, "Not yet frozen!");
@ -3629,7 +3629,7 @@ bool WorkerPrivate::ThawInternal() {
}
void WorkerPrivate::PropagateStorageAccessPermissionGrantedInternal() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
mLoadInfo.mUseRegularPrincipal = true;
mLoadInfo.mHasStorageAccessPermissionGranted = true;
@ -3645,7 +3645,7 @@ void WorkerPrivate::PropagateStorageAccessPermissionGrantedInternal() {
}
void WorkerPrivate::TraverseTimeouts(nsCycleCollectionTraversalCallback& cb) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
for (uint32_t i = 0; i < data->mTimeouts.Length(); ++i) {
// TODO(erahm): No idea what's going on here.
TimeoutInfo* tmp = data->mTimeouts[i].get();
@ -3654,7 +3654,7 @@ void WorkerPrivate::TraverseTimeouts(nsCycleCollectionTraversalCallback& cb) {
}
void WorkerPrivate::UnlinkTimeouts() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
data->mTimeouts.Clear();
}
@ -3677,7 +3677,7 @@ bool WorkerPrivate::ModifyBusyCountFromWorker(bool aIncrease) {
}
bool WorkerPrivate::AddChildWorker(WorkerPrivate* aChildWorker) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
#ifdef DEBUG
{
@ -3700,7 +3700,7 @@ bool WorkerPrivate::AddChildWorker(WorkerPrivate* aChildWorker) {
}
void WorkerPrivate::RemoveChildWorker(WorkerPrivate* aChildWorker) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
NS_ASSERTION(data->mChildWorkers.Contains(aChildWorker),
"Didn't know about this one!");
@ -3714,7 +3714,7 @@ void WorkerPrivate::RemoveChildWorker(WorkerPrivate* aChildWorker) {
bool WorkerPrivate::AddWorkerRef(WorkerRef* aWorkerRef,
WorkerStatus aFailStatus) {
MOZ_ASSERT(aWorkerRef);
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
{
MutexAutoLock lock(mMutex);
@ -3750,7 +3750,7 @@ bool WorkerPrivate::AddWorkerRef(WorkerRef* aWorkerRef,
void WorkerPrivate::RemoveWorkerRef(WorkerRef* aWorkerRef) {
MOZ_ASSERT(aWorkerRef);
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(data->mWorkerRefs.Contains(aWorkerRef),
"Didn't know about this one!");
@ -3766,7 +3766,7 @@ void WorkerPrivate::RemoveWorkerRef(WorkerRef* aWorkerRef) {
}
void WorkerPrivate::NotifyWorkerRefs(WorkerStatus aStatus) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
NS_ASSERTION(aStatus > Closing, "Bad status!");
@ -3785,7 +3785,7 @@ void WorkerPrivate::NotifyWorkerRefs(WorkerStatus aStatus) {
}
void WorkerPrivate::CancelAllTimeouts() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
LOG(TimeoutsLog(), ("Worker %p CancelAllTimeouts.\n", this));
@ -4203,7 +4203,7 @@ void WorkerPrivate::PostMessageToParent(
}
void WorkerPrivate::EnterDebuggerEventLoop() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
JSContext* cx = GetJSContext();
MOZ_ASSERT(cx);
@ -4276,7 +4276,7 @@ void WorkerPrivate::EnterDebuggerEventLoop() {
}
void WorkerPrivate::LeaveDebuggerEventLoop() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
// TODO: Why lock the mutex if we're accessing data accessible to one thread
// only?
@ -4309,7 +4309,7 @@ void WorkerPrivate::ReportErrorToDebugger(const nsAString& aFilename,
}
bool WorkerPrivate::NotifyInternal(WorkerStatus aStatus) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
// Yield execution while notifying out-of-module WorkerRefs and cancelling
// runnables.
@ -4416,7 +4416,7 @@ bool WorkerPrivate::NotifyInternal(WorkerStatus aStatus) {
void WorkerPrivate::ReportError(JSContext* aCx,
JS::ConstUTF8CharsZ aToStringResult,
JSErrorReport* aReport) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (!MayContinueRunning() || data->mErrorHandlerRecursionCount == 2) {
return;
@ -4503,7 +4503,7 @@ void WorkerPrivate::ReportErrorToConsole(const char* aMessage,
int32_t WorkerPrivate::SetTimeout(JSContext* aCx, TimeoutHandler* aHandler,
int32_t aTimeout, bool aIsInterval,
ErrorResult& aRv) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(aHandler);
const int32_t timerId = data->mNextTimeoutId++;
@ -4575,7 +4575,7 @@ int32_t WorkerPrivate::SetTimeout(JSContext* aCx, TimeoutHandler* aHandler,
}
void WorkerPrivate::ClearTimeout(int32_t aId) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (!data->mTimeouts.IsEmpty()) {
NS_ASSERTION(data->mTimerRunning, "Huh?!");
@ -4591,7 +4591,7 @@ void WorkerPrivate::ClearTimeout(int32_t aId) {
}
bool WorkerPrivate::RunExpiredTimeouts(JSContext* aCx) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
// We may be called recursively (e.g. close() inside a timeout) or we could
// have been canceled while this event was pending, bail out if there is
@ -4718,7 +4718,7 @@ bool WorkerPrivate::RunExpiredTimeouts(JSContext* aCx) {
}
bool WorkerPrivate::RescheduleTimeoutTimer(JSContext* aCx) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(!data->mRunningExpiredTimeouts);
NS_ASSERTION(!data->mTimeouts.IsEmpty(), "Should have some timeouts!");
NS_ASSERTION(data->mTimer && data->mTimerRunnable, "Should have a timer!");
@ -4789,7 +4789,7 @@ void WorkerPrivate::StartCancelingTimer() {
void WorkerPrivate::UpdateContextOptionsInternal(
JSContext* aCx, const JS::ContextOptions& aContextOptions) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
JS::ContextOptionsRef(aCx) = aContextOptions;
@ -4806,7 +4806,7 @@ void WorkerPrivate::UpdateLanguagesInternal(
nav->SetLanguages(aLanguages);
}
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
for (uint32_t index = 0; index < data->mChildWorkers.Length(); index++) {
data->mChildWorkers[index]->UpdateLanguages(aLanguages);
}
@ -4821,7 +4821,7 @@ void WorkerPrivate::UpdateLanguagesInternal(
void WorkerPrivate::UpdateJSWorkerMemoryParameterInternal(
JSContext* aCx, JSGCParamKey aKey, Maybe<uint32_t> aValue) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (aValue) {
JS_SetGCParameter(aCx, aKey, *aValue);
@ -4837,7 +4837,7 @@ void WorkerPrivate::UpdateJSWorkerMemoryParameterInternal(
#ifdef JS_GC_ZEAL
void WorkerPrivate::UpdateGCZealInternal(JSContext* aCx, uint8_t aGCZeal,
uint32_t aFrequency) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
JS_SetGCZeal(aCx, aGCZeal, aFrequency);
@ -4848,7 +4848,7 @@ void WorkerPrivate::UpdateGCZealInternal(JSContext* aCx, uint8_t aGCZeal,
#endif
void WorkerPrivate::SetLowMemoryStateInternal(JSContext* aCx, bool aState) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
JS::SetLowMemoryState(aCx, aState);
@ -4859,7 +4859,7 @@ void WorkerPrivate::SetLowMemoryStateInternal(JSContext* aCx, bool aState) {
void WorkerPrivate::GarbageCollectInternal(JSContext* aCx, bool aShrinking,
bool aCollectChildren) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (!GlobalScope()) {
// We haven't compiled anything yet. Just bail out.
@ -4892,7 +4892,7 @@ void WorkerPrivate::GarbageCollectInternal(JSContext* aCx, bool aShrinking,
}
void WorkerPrivate::CycleCollectInternal(bool aCollectChildren) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
nsCycleCollector_collect(nullptr);
@ -4904,7 +4904,7 @@ void WorkerPrivate::CycleCollectInternal(bool aCollectChildren) {
}
void WorkerPrivate::MemoryPressureInternal() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (data->mScope) {
RefPtr<Console> console = data->mScope->GetConsoleIfExists();
@ -4985,7 +4985,7 @@ void WorkerPrivate::ResetWorkerPrivateInWorkerThread() {
void WorkerPrivate::BeginCTypesCall() {
AssertIsOnWorkerThread();
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
// Don't try to GC while we're blocked in a ctypes call.
SetGCTimerMode(NoTimer);
@ -4995,7 +4995,7 @@ void WorkerPrivate::BeginCTypesCall() {
void WorkerPrivate::EndCTypesCall() {
AssertIsOnWorkerThread();
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
data->mYieldJSThreadExecution.RemoveLastElement();
@ -5063,7 +5063,7 @@ bool WorkerPrivate::ConnectMessagePort(JSContext* aCx,
}
WorkerGlobalScope* WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
if (data->mScope) {
return data->mScope;
@ -5098,7 +5098,7 @@ WorkerGlobalScope* WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx) {
WorkerDebuggerGlobalScope* WorkerPrivate::CreateDebuggerGlobalScope(
JSContext* aCx) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
MOZ_ASSERT(!data->mDebuggerScope);
// The debugger global gets a dummy client, not the "real" client used by the
@ -5141,7 +5141,7 @@ void WorkerPrivate::AssertIsOnWorkerThread() const {
#endif // DEBUG
void WorkerPrivate::DumpCrashInformation(nsACString& aString) {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
for (const auto* workerRef : data->mWorkerRefs.NonObservingRange()) {
if (workerRef->IsPreventingShutdown()) {
@ -5463,7 +5463,7 @@ WorkerPrivate::EventTarget::IsOnCurrentThreadInfallible() {
WorkerPrivate::AutoPushEventLoopGlobal::AutoPushEventLoopGlobal(
WorkerPrivate* aWorkerPrivate, JSContext* aCx)
: mWorkerPrivate(aWorkerPrivate) {
MOZ_ACCESS_THREAD_BOUND(mWorkerPrivate->mWorkerThreadAccessible, data);
auto data = mWorkerPrivate->mWorkerThreadAccessible.Access();
mOldEventLoopGlobal = std::move(data->mCurrentEventLoopGlobal);
if (JSObject* global = JS::CurrentGlobalOrNull(aCx)) {
data->mCurrentEventLoopGlobal = xpc::NativeGlobal(global);
@ -5471,7 +5471,7 @@ WorkerPrivate::AutoPushEventLoopGlobal::AutoPushEventLoopGlobal(
}
WorkerPrivate::AutoPushEventLoopGlobal::~AutoPushEventLoopGlobal() {
MOZ_ACCESS_THREAD_BOUND(mWorkerPrivate->mWorkerThreadAccessible, data);
auto data = mWorkerPrivate->mWorkerThreadAccessible.Access();
data->mCurrentEventLoopGlobal = std::move(mOldEventLoopGlobal);
}

Просмотреть файл

@ -341,12 +341,12 @@ class WorkerPrivate : public RelativeTimeline {
}
WorkerGlobalScope* GlobalScope() const {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return data->mScope;
}
WorkerDebuggerGlobalScope* DebuggerGlobalScope() const {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return data->mDebuggerScope;
}
@ -354,7 +354,7 @@ class WorkerPrivate : public RelativeTimeline {
// null if we're not in a nested event loop or that nested event loop does not
// have an associated global.
nsIGlobalObject* GetCurrentEventLoopGlobal() const {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return data->mCurrentEventLoopGlobal;
}
@ -397,7 +397,7 @@ class WorkerPrivate : public RelativeTimeline {
bool RegisterDebuggerBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
bool OnLine() const {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return data->mOnLine;
}
@ -1038,7 +1038,7 @@ class WorkerPrivate : public RelativeTimeline {
void NotifyWorkerRefs(WorkerStatus aStatus);
bool HasActiveWorkerRefs() {
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
auto data = mWorkerThreadAccessible.Access();
return !(data->mChildWorkers.IsEmpty() && data->mTimeouts.IsEmpty() &&
data->mWorkerRefs.IsEmpty());
}

Просмотреть файл

@ -270,7 +270,7 @@ nsISerialEventTarget* RemoteWorkerChild::GetOwningEventTarget() const {
}
void RemoteWorkerChild::ActorDestroy(ActorDestroyReason) {
MOZ_ACCESS_THREAD_BOUND(mLauncherData, launcherData);
auto launcherData = mLauncherData.Access();
launcherData->mIPCActive = false;
Unused << NS_WARN_IF(!launcherData->mTerminationPromise.IsEmpty());
@ -287,7 +287,7 @@ void RemoteWorkerChild::ActorDestroy(ActorDestroyReason) {
void RemoteWorkerChild::ExecWorker(const RemoteWorkerData& aData) {
#ifdef DEBUG
MOZ_ASSERT(GetOwningEventTarget()->IsOnCurrentThread());
MOZ_ACCESS_THREAD_BOUND(mLauncherData, launcherData);
auto launcherData = mLauncherData.Access();
MOZ_ASSERT(launcherData->mIPCActive);
#endif
@ -567,7 +567,7 @@ void RemoteWorkerChild::ShutdownOnWorker() {
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction(__func__, [self = std::move(self)] {
MOZ_ACCESS_THREAD_BOUND(self->mLauncherData, launcherData);
auto launcherData = self->mLauncherData.Access();
if (!launcherData->mIPCActive) {
return;
@ -581,7 +581,7 @@ void RemoteWorkerChild::ShutdownOnWorker() {
}
RefPtr<GenericNonExclusivePromise> RemoteWorkerChild::GetTerminationPromise() {
MOZ_ACCESS_THREAD_BOUND(mLauncherData, launcherData);
auto launcherData = mLauncherData.Access();
return launcherData->mTerminationPromise.Ensure(__func__);
}
@ -606,7 +606,7 @@ void RemoteWorkerChild::CreationSucceededOrFailedOnAnyThread(
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
__func__,
[self = std::move(self), didCreationSucceed = aDidCreationSucceed] {
MOZ_ACCESS_THREAD_BOUND(self->mLauncherData, launcherData);
auto launcherData = self->mLauncherData.Access();
if (!launcherData->mIPCActive) {
return;
@ -642,7 +642,7 @@ void RemoteWorkerChild::CloseWorkerOnMainThread(State& aState) {
void RemoteWorkerChild::ErrorPropagation(const ErrorValue& aValue) {
MOZ_ASSERT(GetOwningEventTarget()->IsOnCurrentThread());
MOZ_ACCESS_THREAD_BOUND(mLauncherData, launcherData);
auto launcherData = mLauncherData.Access();
if (!launcherData->mIPCActive) {
return;
@ -812,7 +812,7 @@ void RemoteWorkerChild::TransitionStateToTerminated(State& aState) {
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction(__func__, [self = SelfHolder(this)]() {
MOZ_ACCESS_THREAD_BOUND(self->mLauncherData, launcherData);
auto launcherData = self->mLauncherData.Access();
launcherData->mTerminationPromise.ResolveIfExists(true, __func__);
});
@ -839,7 +839,7 @@ class RemoteWorkerChild::SharedWorkerOp : public RemoteWorkerChild::Op {
MOZ_ASSERT(!mStarted);
MOZ_ASSERT(aOwner);
MOZ_ACCESS_THREAD_BOUND(aOwner->mLauncherData, launcherData);
auto launcherData = aOwner->mLauncherData.Access();
if (NS_WARN_IF(!launcherData->mIPCActive)) {
Unused << NS_WARN_IF(!aState.is<Terminated>());
@ -1018,7 +1018,7 @@ RemoteWorkerChild::MaybeSendSetServiceWorkerSkipWaitingFlag() {
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(__func__, [self = std::move(
self),
promise] {
MOZ_ACCESS_THREAD_BOUND(self->mLauncherData, launcherData);
auto launcherData = self->mLauncherData.Access();
if (!launcherData->mIPCActive) {
promise->Reject(NS_ERROR_DOM_ABORT_ERR, __func__);

Просмотреть файл

@ -722,7 +722,7 @@ nsresult PermissionManager::Init() {
nsresult PermissionManager::OpenDatabase(nsIFile* aPermissionsFile) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ACCESS_THREAD_BOUND(mThreadBoundData, data);
auto data = mThreadBoundData.Access();
nsresult rv;
nsCOMPtr<mozIStorageService> storage =
@ -805,7 +805,7 @@ nsresult PermissionManager::TryInitDB(bool aRemoveFile,
mState = eDBInitialized;
});
MOZ_ACCESS_THREAD_BOUND(mThreadBoundData, data);
auto data = mThreadBoundData.Access();
auto raiiFailure = MakeScopeExit([&]() {
if (data->mDBConn) {
@ -1432,7 +1432,7 @@ void PermissionManager::PerformIdleDailyMaintenance() {
RefPtr<PermissionManager> self = this;
mThread->Dispatch(NS_NewRunnableFunction(
"PermissionManager::PerformIdleDailyMaintenance", [self] {
MOZ_ACCESS_THREAD_BOUND(self->mThreadBoundData, data);
auto data = self->mThreadBoundData.Access();
if (self->mState == eClosed || !data->mDBConn) {
return;
@ -1460,7 +1460,7 @@ void PermissionManager::PerformIdleDailyMaintenance() {
// sets the schema version and creates the moz_perms table.
nsresult PermissionManager::CreateTable() {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ACCESS_THREAD_BOUND(mThreadBoundData, data);
auto data = mThreadBoundData.Access();
// set the schema version, before creating the table
nsresult rv = data->mDBConn->SetSchemaVersion(HOSTS_SCHEMA_VERSION);
@ -2009,7 +2009,7 @@ void PermissionManager::CloseDB(bool aRebuildOnSuccess) {
mThread->Dispatch(NS_NewRunnableFunction(
"PermissionManager::CloseDB",
[self, aRebuildOnSuccess, defaultsInputStream] {
MOZ_ACCESS_THREAD_BOUND(self->mThreadBoundData, data);
auto data = self->mThreadBoundData.Access();
// Null the statements, this will finalize them.
data->mStmtInsert = nullptr;
data->mStmtDelete = nullptr;
@ -2064,7 +2064,7 @@ nsresult PermissionManager::RemoveAllInternal(bool aNotifyObservers) {
RefPtr<PermissionManager> self = this;
mThread->Dispatch(
NS_NewRunnableFunction("PermissionManager::RemoveAllInternal", [self] {
MOZ_ACCESS_THREAD_BOUND(self->mThreadBoundData, data);
auto data = self->mThreadBoundData.Access();
if (self->mState == eClosed || !data->mDBConn) {
return;
@ -2660,7 +2660,7 @@ nsresult PermissionManager::Read(const MonitorAutoLock& aProofOfLock) {
ENSURE_NOT_CHILD_PROCESS;
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ACCESS_THREAD_BOUND(mThreadBoundData, data);
auto data = mThreadBoundData.Access();
nsresult rv;
@ -2828,7 +2828,7 @@ void PermissionManager::UpdateDB(OperationType aOp, int64_t aID,
aModificationTime] {
nsresult rv;
MOZ_ACCESS_THREAD_BOUND(self->mThreadBoundData, data);
auto data = self->mThreadBoundData.Access();
if (self->mState == eClosed || !data->mDBConn) {
// no statement is ok - just means we don't have a profile

Просмотреть файл

@ -36,7 +36,7 @@ struct AddConstIf<true, T> {
// through a non-copyable, immovable accessor object.
// Given a ThreadBound<T> threadBoundData, it can be accessed like so:
//
// MOZ_ACCESS_THREAD_BOUND(threadBoundData, innerData);
// auto innerData = threadBoundData.Access();
// innerData->DoStuff();
//
// Trying to access a ThreadBound<T> from a different thread will
@ -120,9 +120,9 @@ class ThreadBound final {
AccessCountType& mAccessCount;
};
template <typename U>
using AccessorFor =
Accessor<std::is_const<typename std::remove_reference<U>::type>::value>;
auto Access() { return Accessor<false>{*this}; }
auto Access() const { return Accessor<true>{*this}; }
private:
bool IsCorrectThread() const { return mThread == PR_GetCurrentThread(); }
@ -138,9 +138,6 @@ class ThreadBound final {
#undef MOZ_DEFINE_THREAD_BOUND_ASSERT
};
#define MOZ_ACCESS_THREAD_BOUND(value, name) \
decltype(value)::AccessorFor<decltype(*&value)> name(value)
} // namespace mozilla
#endif // mozilla_ThreadBound_h