Skip to content

Commit

Permalink
Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-revie…
Browse files Browse the repository at this point in the history
…wers,media-playback-reviewers,alwu,jesup,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D152575
  • Loading branch information
AndreeaPavel committed Aug 3, 2022
1 parent a6c6330 commit ff02a4b
Show file tree
Hide file tree
Showing 202 changed files with 1,525 additions and 1,450 deletions.
2 changes: 1 addition & 1 deletion docshell/base/timeline/ObservedDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ObservedDocShell : public MarkersStorage {
// Off the main thread only.
Mutex mLock;
nsTArray<UniquePtr<AbstractTimelineMarker>> mOffTheMainThreadTimelineMarkers
GUARDED_BY(mLock);
MOZ_GUARDED_BY(mLock);

public:
explicit ObservedDocShell(nsIDocShell* aDocShell);
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/timeline/TimelineConsumers.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class TimelineConsumers {
private:
static StaticMutex sMutex;

static LinkedList<MarkersStorage>& MarkersStores() REQUIRES(sMutex);
static LinkedList<MarkersStorage>& MarkersStores() MOZ_REQUIRES(sMutex);

static uint32_t sActiveConsumers GUARDED_BY(sMutex);
static uint32_t sActiveConsumers MOZ_GUARDED_BY(sMutex);
static StaticAutoPtr<LinkedList<MarkersStorage>> sMarkersStores
GUARDED_BY(sMutex);
MOZ_GUARDED_BY(sMutex);
};

} // namespace mozilla
Expand Down
6 changes: 3 additions & 3 deletions dom/base/BodyStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
MOZ_ASSERT(workerPrivate);

RefPtr<StrongWorkerRef> workerRef =
StrongWorkerRef::Create(workerPrivate, "BodyStream", [stream]() { stream->Close(); });
RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(
workerPrivate, "BodyStream", [stream]() { stream->Close(); });

if (NS_WARN_IF(!workerRef)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
Expand Down Expand Up @@ -428,7 +428,7 @@ void BodyStream::EnqueueChunkWithSizeIntoStream(JSContext* aCx,
// thread-safety doesn't handle emplace well
NS_IMETHODIMP
BodyStream::OnInputStreamReady(nsIAsyncInputStream* aStream)
NO_THREAD_SAFETY_ANALYSIS {
MOZ_NO_THREAD_SAFETY_ANALYSIS {
AssertIsOnOwningThread();
MOZ_DIAGNOSTIC_ASSERT(aStream);
mAsyncWaitWorkerRef = nullptr;
Expand Down
11 changes: 6 additions & 5 deletions dom/base/BodyStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ class BodyStream final : public nsIInputStreamCallback,

void ErrorPropagation(JSContext* aCx,
const MutexSingleWriterAutoLock& aProofOfLock,
ReadableStream* aStream, nsresult aRv) REQUIRES(mMutex);
ReadableStream* aStream, nsresult aRv)
MOZ_REQUIRES(mMutex);

// TODO: convert this to MOZ_CAN_RUN_SCRIPT (bug 1750605)
MOZ_CAN_RUN_SCRIPT_BOUNDARY void CloseAndReleaseObjects(
JSContext* aCx, const MutexSingleWriterAutoLock& aProofOfLock,
ReadableStream* aStream) REQUIRES(mMutex);
ReadableStream* aStream) MOZ_REQUIRES(mMutex);

class WorkerShutdown;

void ReleaseObjects(const MutexSingleWriterAutoLock& aProofOfLock)
REQUIRES(mMutex);
MOZ_REQUIRES(mMutex);

void ReleaseObjects();

Expand Down Expand Up @@ -186,12 +187,12 @@ class BodyStream final : public nsIInputStreamCallback,
MutexSingleWriter mMutex;

// Protected by mutex.
State mState GUARDED_BY(mMutex); // all writes are from the owning thread
State mState MOZ_GUARDED_BY(mMutex); // all writes are from the owning thread

// mGlobal is set on creation, and isn't modified off the owning thread.
// It isn't set to nullptr until ReleaseObjects() runs.
nsCOMPtr<nsIGlobalObject> mGlobal;
RefPtr<BodyStreamHolder> mStreamHolder GUARDED_BY(mMutex);
RefPtr<BodyStreamHolder> mStreamHolder MOZ_GUARDED_BY(mMutex);
nsCOMPtr<nsIEventTarget> mOwningEventTarget;

// This is the original inputStream received during the CTOR. It will be
Expand Down
4 changes: 2 additions & 2 deletions dom/canvas/WebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class WebGLContext : public VRefCounted, public SupportsWeakPtr {
~LruPosition() { Reset(); }
};

mutable LruPosition mLruPosition GUARDED_BY(sLruMutex);
mutable LruPosition mLruPosition MOZ_GUARDED_BY(sLruMutex);

void BumpLruLocked(const StaticMutexAutoLock& aProofOfLock);

Expand Down Expand Up @@ -740,7 +740,7 @@ class WebGLContext : public VRefCounted, public SupportsWeakPtr {

private:
static StaticMutex sLruMutex;
static std::list<WebGLContext*> sLru GUARDED_BY(sLruMutex);
static std::list<WebGLContext*> sLru MOZ_GUARDED_BY(sLruMutex);

// State tracking slots
bool mDitherEnabled = true;
Expand Down
2 changes: 1 addition & 1 deletion dom/console/ConsoleReportCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ConsoleReportCollector final : public nsIConsoleReportCollector {
Mutex mMutex;

// protected by mMutex
nsTArray<PendingReport> mPendingReports GUARDED_BY(mMutex);
nsTArray<PendingReport> mPendingReports MOZ_GUARDED_BY(mMutex);

public:
NS_DECL_THREADSAFE_ISUPPORTS
Expand Down
29 changes: 16 additions & 13 deletions dom/file/ipc/RemoteLazyInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,

~RemoteLazyInputStream();

void StreamNeeded() REQUIRES(mMutex);
void StreamNeeded() MOZ_REQUIRES(mMutex);

// Upon receiving the stream from our actor, we will not wrap it into an async
// stream until needed. This allows callers to get access to the underlying
// potentially-sync stream using `TakeInternalStream` before reading.
nsresult EnsureAsyncRemoteStream() REQUIRES(mMutex);
nsresult EnsureAsyncRemoteStream() MOZ_REQUIRES(mMutex);

// Note that data has been read from our input stream, and disconnect from our
// remote actor.
Expand All @@ -82,7 +82,7 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,
IPC::MessageReader* aReader);

// Helper method to generate a description of a stream for use in loggging.
nsCString Describe() REQUIRES(mMutex);
nsCString Describe() MOZ_REQUIRES(mMutex);

// Start and length of the slice to apply on this RemoteLazyInputStream when
// fetching the underlying stream with `SendStreamNeeded`.
Expand Down Expand Up @@ -112,7 +112,7 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,
// mInnerStream is released and any method will return
// NS_BASE_STREAM_CLOSED.
eClosed,
} mState GUARDED_BY(mMutex) = eClosed;
} mState MOZ_GUARDED_BY(mMutex) = eClosed;

// The actor which will be used to provide the underlying stream or length
// information when needed, as well as to efficiently allow transferring the
Expand All @@ -121,22 +121,25 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,
// The connection to our actor will be cleared once the stream has been closed
// or has started reading, at which point this stream will be serialized and
// cloned as-if it was the underlying stream.
RefPtr<RemoteLazyInputStreamChild> mActor GUARDED_BY(mMutex);
RefPtr<RemoteLazyInputStreamChild> mActor MOZ_GUARDED_BY(mMutex);

nsCOMPtr<nsIInputStream> mInnerStream GUARDED_BY(mMutex);
nsCOMPtr<nsIAsyncInputStream> mAsyncInnerStream GUARDED_BY(mMutex);
nsCOMPtr<nsIInputStream> mInnerStream MOZ_GUARDED_BY(mMutex);
nsCOMPtr<nsIAsyncInputStream> mAsyncInnerStream MOZ_GUARDED_BY(mMutex);

// These 2 values are set only if mState is ePending or eRunning.
// RefPtr is used instead of nsCOMPtr to avoid invoking QueryInterface when
// assigning in debug builds, as `mInputStreamCallback` may not be threadsafe.
RefPtr<nsIInputStreamCallback> mInputStreamCallback GUARDED_BY(mMutex);
nsCOMPtr<nsIEventTarget> mInputStreamCallbackEventTarget GUARDED_BY(mMutex);
uint32_t mInputStreamCallbackFlags GUARDED_BY(mMutex) = 0;
uint32_t mInputStreamCallbackRequestedCount GUARDED_BY(mMutex) = 0;
RefPtr<nsIInputStreamCallback> mInputStreamCallback MOZ_GUARDED_BY(mMutex);
nsCOMPtr<nsIEventTarget> mInputStreamCallbackEventTarget
MOZ_GUARDED_BY(mMutex);
uint32_t mInputStreamCallbackFlags MOZ_GUARDED_BY(mMutex) = 0;
uint32_t mInputStreamCallbackRequestedCount MOZ_GUARDED_BY(mMutex) = 0;

// These 2 values are set only if mState is ePending.
nsCOMPtr<nsIFileMetadataCallback> mFileMetadataCallback GUARDED_BY(mMutex);
nsCOMPtr<nsIEventTarget> mFileMetadataCallbackEventTarget GUARDED_BY(mMutex);
nsCOMPtr<nsIFileMetadataCallback> mFileMetadataCallback
MOZ_GUARDED_BY(mMutex);
nsCOMPtr<nsIEventTarget> mFileMetadataCallbackEventTarget
MOZ_GUARDED_BY(mMutex);
};

} // namespace mozilla
Expand Down
35 changes: 18 additions & 17 deletions dom/ipc/ProcessHangMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,22 @@ class HangMonitorChild : public PProcessHangMonitorChild,
bool mSentReport;

// These fields must be accessed with mMonitor held.
bool mTerminateScript GUARDED_BY(mMonitor);
bool mStartDebugger GUARDED_BY(mMonitor);
bool mFinishedStartingDebugger GUARDED_BY(mMonitor);
bool mPaintWhileInterruptingJS GUARDED_BY(mMonitor);
TabId mPaintWhileInterruptingJSTab GUARDED_BY(mMonitor);
bool mTerminateScript MOZ_GUARDED_BY(mMonitor);
bool mStartDebugger MOZ_GUARDED_BY(mMonitor);
bool mFinishedStartingDebugger MOZ_GUARDED_BY(mMonitor);
bool mPaintWhileInterruptingJS MOZ_GUARDED_BY(mMonitor);
TabId mPaintWhileInterruptingJSTab MOZ_GUARDED_BY(mMonitor);
MOZ_INIT_OUTSIDE_CTOR LayersObserverEpoch mPaintWhileInterruptingJSEpoch
GUARDED_BY(mMonitor);
bool mCancelContentJS GUARDED_BY(mMonitor);
TabId mCancelContentJSTab GUARDED_BY(mMonitor);
MOZ_GUARDED_BY(mMonitor);
bool mCancelContentJS MOZ_GUARDED_BY(mMonitor);
TabId mCancelContentJSTab MOZ_GUARDED_BY(mMonitor);
nsIRemoteTab::NavigationType mCancelContentJSNavigationType
GUARDED_BY(mMonitor);
int32_t mCancelContentJSNavigationIndex GUARDED_BY(mMonitor);
mozilla::Maybe<nsCString> mCancelContentJSNavigationURI GUARDED_BY(mMonitor);
int32_t mCancelContentJSEpoch GUARDED_BY(mMonitor);
bool mShutdownDone GUARDED_BY(mMonitor);
MOZ_GUARDED_BY(mMonitor);
int32_t mCancelContentJSNavigationIndex MOZ_GUARDED_BY(mMonitor);
mozilla::Maybe<nsCString> mCancelContentJSNavigationURI
MOZ_GUARDED_BY(mMonitor);
int32_t mCancelContentJSEpoch MOZ_GUARDED_BY(mMonitor);
bool mShutdownDone MOZ_GUARDED_BY(mMonitor);

JSContext* mContext; // const after constructor

Expand Down Expand Up @@ -293,14 +294,14 @@ class HangMonitorParent : public PProcessHangMonitorParent,
RefPtr<HangMonitoredProcess> mProcess;

// Must be accessed with mMonitor held.
bool mShutdownDone GUARDED_BY(mMonitor);
bool mShutdownDone MOZ_GUARDED_BY(mMonitor);
// Map from plugin ID to crash dump ID. Protected by
// mBrowserCrashDumpHashLock.
nsTHashMap<nsUint32HashKey, nsString> mBrowserCrashDumpIds
GUARDED_BY(mMonitor);
Mutex mBrowserCrashDumpHashLock GUARDED_BY(mMonitor);
MOZ_GUARDED_BY(mMonitor);
Mutex mBrowserCrashDumpHashLock MOZ_GUARDED_BY(mMonitor);
mozilla::ipc::TaskFactory<HangMonitorParent> mMainThreadTaskFactory
GUARDED_BY(mMonitor);
MOZ_GUARDED_BY(mMonitor);
};

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion dom/media/AudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int AudioStream::InvokeCubeb(Function aFunction, Args&&... aArgs) {
}

nsresult AudioStream::Init(AudioDeviceInfo* aSinkInfo)
NO_THREAD_SAFETY_ANALYSIS {
MOZ_NO_THREAD_SAFETY_ANALYSIS {
auto startTime = TimeStamp::Now();
TRACE("AudioStream::Init");

Expand Down
9 changes: 5 additions & 4 deletions dom/media/AudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class AudioClock {
// protected by the AudioStream monitor on other platforms.
const UniquePtr<FrameHistory> mFrameHistory
# ifndef XP_MACOSX
GUARDED_BY(mMutex)
MOZ_GUARDED_BY(mMutex)
# endif
;
# ifdef XP_MACOSX
Expand Down Expand Up @@ -335,10 +335,10 @@ class AudioStream final {

// Return true if audio frames are valid (correct sampling rate and valid
// channel count) otherwise false.
bool IsValidAudioFormat(Chunk* aChunk) REQUIRES(mMonitor);
bool IsValidAudioFormat(Chunk* aChunk) MOZ_REQUIRES(mMonitor);

template <typename Function, typename... Args>
int InvokeCubeb(Function aFunction, Args&&... aArgs) REQUIRES(mMonitor);
int InvokeCubeb(Function aFunction, Args&&... aArgs) MOZ_REQUIRES(mMonitor);
bool CheckThreadIdChanged();
void AssertIsOnAudioThread() const;

Expand Down Expand Up @@ -382,7 +382,8 @@ class AudioStream final {
std::atomic<ProfilerThreadId> mAudioThreadId;
const bool mSandboxed = false;

MozPromiseHolder<MediaSink::EndedPromise> mEndedPromise GUARDED_BY(mMonitor);
MozPromiseHolder<MediaSink::EndedPromise> mEndedPromise
MOZ_GUARDED_BY(mMonitor);
std::atomic<bool> mPlaybackComplete;
// Both written on the MDSM thread, read on the audio thread.
std::atomic<float> mPlaybackRate;
Expand Down
16 changes: 8 additions & 8 deletions dom/media/FileBlockCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ class FileBlockCache : public MediaBlockCacheBase {
nsresult WriteBlockToFile(int32_t aBlockIndex, const uint8_t* aBlockData);
// File descriptor we're writing to. This is created externally, but
// shutdown by us.
PRFileDesc* mFD PT_GUARDED_BY(mFileMutex);
PRFileDesc* mFD MOZ_PT_GUARDED_BY(mFileMutex);
// The current file offset in the file.
int64_t mFDCurrentPos GUARDED_BY(mFileMutex);
int64_t mFDCurrentPos MOZ_GUARDED_BY(mFileMutex);

// Mutex which controls access to all data in this class, except mFD
// and mFDCurrentPos. Don't hold mDataMutex while holding mFileMutex!
Expand All @@ -170,22 +170,22 @@ class FileBlockCache : public MediaBlockCacheBase {
// mBlockChanges[offset/BLOCK_SIZE] != nullptr, then either there's a block
// cached in memory waiting to be written, or this block is the target of a
// block move.
nsTArray<RefPtr<BlockChange> > mBlockChanges GUARDED_BY(mDataMutex);
nsTArray<RefPtr<BlockChange> > mBlockChanges MOZ_GUARDED_BY(mDataMutex);
// Event target upon which block writes and block moves are performed. This is
// created upon open, and dropped on close.
nsCOMPtr<nsISerialEventTarget> mBackgroundET GUARDED_BY(mDataMutex);
nsCOMPtr<nsISerialEventTarget> mBackgroundET MOZ_GUARDED_BY(mDataMutex);
// Queue of pending block indexes that need to be written or moved.
std::deque<int32_t> mChangeIndexList GUARDED_BY(mDataMutex);
std::deque<int32_t> mChangeIndexList MOZ_GUARDED_BY(mDataMutex);
// True if we've dispatched an event to commit all pending block changes
// to file on mBackgroundET.
bool mIsWriteScheduled GUARDED_BY(mDataMutex);
bool mIsWriteScheduled MOZ_GUARDED_BY(mDataMutex);
// True when a read is happening. Pending writes may be postponed, to give
// higher priority to reads (which may be blocking the caller).
bool mIsReading GUARDED_BY(mDataMutex);
bool mIsReading MOZ_GUARDED_BY(mDataMutex);
// True if we've got a temporary file descriptor. Note: we don't use mFD
// directly as that's synchronized via mFileMutex and we need to make
// decisions about whether we can write while holding mDataMutex.
bool mInitialized GUARDED_BY(mDataMutex) = false;
bool mInitialized MOZ_GUARDED_BY(mDataMutex) = false;
};

} // End namespace mozilla.
Expand Down
16 changes: 8 additions & 8 deletions dom/media/FileMediaResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ class FileMediaResource : public BaseMediaResource {
// calling. The implmentation of Read, Seek and ReadAt obtains the
// lock before calling these Unsafe variants to read or seek.
nsresult UnsafeRead(char* aBuffer, uint32_t aCount, uint32_t* aBytes)
REQUIRES(mLock);
nsresult UnsafeSeek(int32_t aWhence, int64_t aOffset) REQUIRES(mLock);
MOZ_REQUIRES(mLock);
nsresult UnsafeSeek(int32_t aWhence, int64_t aOffset) MOZ_REQUIRES(mLock);

private:
// Ensures mSize is initialized, if it can be.
// mLock must be held when this is called, and mInput must be non-null.
void EnsureSizeInitialized() REQUIRES(mLock);
void EnsureSizeInitialized() MOZ_REQUIRES(mLock);
already_AddRefed<MediaByteBuffer> UnsafeMediaReadAt(int64_t aOffset,
uint32_t aCount)
REQUIRES(mLock);
MOZ_REQUIRES(mLock);

// The file size, or -1 if not known. Immutable after Open().
// Can be used from any thread.
// XXX FIX? is this under mLock? comments are contradictory
int64_t mSize GUARDED_BY(mLock);
int64_t mSize MOZ_GUARDED_BY(mLock);

// This lock handles synchronisation between calls to Close() and
// the Read, Seek, etc calls. Close must not be called while a
Expand All @@ -116,16 +116,16 @@ class FileMediaResource : public BaseMediaResource {

// Seekable stream interface to file. This can be used from any
// thread.
nsCOMPtr<nsISeekableStream> mSeekable GUARDED_BY(mLock);
nsCOMPtr<nsISeekableStream> mSeekable MOZ_GUARDED_BY(mLock);

// Input stream for the media data. This can be used from any
// thread.
nsCOMPtr<nsIInputStream> mInput GUARDED_BY(mLock);
nsCOMPtr<nsIInputStream> mInput MOZ_GUARDED_BY(mLock);

// Whether we've attempted to initialize mSize. Note that mSize can be -1
// when mSizeInitialized is true if we tried and failed to get the size
// of the file.
bool mSizeInitialized GUARDED_BY(mLock);
bool mSizeInitialized MOZ_GUARDED_BY(mLock);
// Set to true if NotifyDataEnded callback has been processed (which only
// occurs if resource size is known)
bool mNotifyDataEndedProcessed = false;
Expand Down
6 changes: 3 additions & 3 deletions dom/media/GraphRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class GraphRunner final : public Runnable {
MediaTrackGraphImpl* const mGraph;
// State being handed over to the graph through OneIteration. Protected by
// mMonitor.
Maybe<IterationState> mIterationState GUARDED_BY(mMonitor);
Maybe<IterationState> mIterationState MOZ_GUARDED_BY(mMonitor);
// Result from mGraph's OneIteration. Protected by mMonitor.
IterationResult mIterationResult GUARDED_BY(mMonitor);
IterationResult mIterationResult MOZ_GUARDED_BY(mMonitor);

enum class ThreadState {
Wait, // Waiting for a message. This is the initial state.
Expand All @@ -100,7 +100,7 @@ class GraphRunner final : public Runnable {
};
// Protected by mMonitor until set to Shutdown, after which this is not
// modified.
ThreadState mThreadState GUARDED_BY(mMonitor);
ThreadState mThreadState MOZ_GUARDED_BY(mMonitor);

// The thread running mGraph. Set on construction, after other members are
// initialized. Cleared at the end of Shutdown().
Expand Down
Loading

0 comments on commit ff02a4b

Please sign in to comment.