Bug 1760357 - Part 4: Add straightforward annotations to IPC types, r=jesup

Differential Revision: https://phabricator.services.mozilla.com/D141535
This commit is contained in:
Nika Layzell 2022-03-22 14:59:41 +00:00
Родитель 6cd1233132
Коммит 8b588479cd
9 изменённых файлов: 36 добавлений и 35 удалений

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

@ -64,8 +64,8 @@ class AtExitManager {
void* param_; void* param_;
}; };
mozilla::Mutex lock_ MOZ_UNANNOTATED; mozilla::Mutex lock_;
std::stack<CallbackAndParam> stack_; std::stack<CallbackAndParam> stack_ GUARDED_BY(lock_);
AtExitManager* next_manager_; // Stack of managers to allow shadowing. AtExitManager* next_manager_; // Stack of managers to allow shadowing.
DISALLOW_COPY_AND_ASSIGN(AtExitManager); DISALLOW_COPY_AND_ASSIGN(AtExitManager);

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

@ -111,8 +111,8 @@ class MessageLoop::EventTarget : public nsISerialEventTarget,
mLoop = nullptr; mLoop = nullptr;
} }
mozilla::Mutex mMutex MOZ_UNANNOTATED; mozilla::Mutex mMutex;
MessageLoop* mLoop; MessageLoop* mLoop GUARDED_BY(mMutex);
}; };
NS_IMPL_ISUPPORTS(MessageLoop::EventTarget, nsIEventTarget, NS_IMPL_ISUPPORTS(MessageLoop::EventTarget, nsIEventTarget,

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

@ -421,9 +421,9 @@ class MessageLoop : public base::MessagePump::Delegate {
// aquired under a mutex for processing on this instance's thread. These tasks // aquired under a mutex for processing on this instance's thread. These tasks
// have not yet been sorted out into items for our work_queue_ vs items that // have not yet been sorted out into items for our work_queue_ vs items that
// will be handled by the TimerManager. // will be handled by the TimerManager.
TaskQueue incoming_queue_; TaskQueue incoming_queue_ GUARDED_BY(incoming_queue_lock_);
// Protect access to incoming_queue_. // Protect access to incoming_queue_.
mozilla::Mutex incoming_queue_lock_ MOZ_UNANNOTATED; mozilla::Mutex incoming_queue_lock_;
RunState* state_; RunState* state_;
int run_depth_base_; int run_depth_base_;

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

@ -209,6 +209,14 @@ DWORD timeGetTimeWrapper() { return timeGetTime(); }
DWORD (*tick_function)(void) = &timeGetTimeWrapper; DWORD (*tick_function)(void) = &timeGetTimeWrapper;
// This setup is a little gross: the `now` instance lives until libxul is
// unloaded, but leak checking runs prior to that, and would see a Mutex
// instance contained in NowSingleton as still live. Said instance would
// be reported as a leak...but it's not, really. To avoid that, we need
// to use StaticMutex (which is not leak-checked), but StaticMutex can't
// be a member variable. So we have to have this separate static variable.
static mozilla::StaticMutex sNowSingletonLock;
// We use timeGetTime() to implement TimeTicks::Now(). This can be problematic // We use timeGetTime() to implement TimeTicks::Now(). This can be problematic
// because it returns the number of milliseconds since Windows has started, // because it returns the number of milliseconds since Windows has started,
// which will roll over the 32-bit value every ~49 days. We try to track // which will roll over the 32-bit value every ~49 days. We try to track
@ -217,7 +225,7 @@ DWORD (*tick_function)(void) = &timeGetTimeWrapper;
class NowSingleton { class NowSingleton {
public: public:
TimeDelta Now() { TimeDelta Now() {
mozilla::StaticMutexAutoLock locked(lock_); mozilla::StaticMutexAutoLock locked(sNowSingletonLock);
// We should hold the lock while calling tick_function to make sure that // We should hold the lock while calling tick_function to make sure that
// we keep our last_seen_ stay correctly in sync. // we keep our last_seen_ stay correctly in sync.
DWORD now = tick_function(); DWORD now = tick_function();
@ -229,28 +237,20 @@ class NowSingleton {
} }
static NowSingleton& instance() { static NowSingleton& instance() {
// This setup is a little gross: the `now` instance lives until libxul is static NowSingleton now;
// unloaded, but leak checking runs prior to that, and would see a Mutex
// instance contained in NowSingleton as still live. Said instance would
// be reported as a leak...but it's not, really. To avoid that, we need
// to use StaticMutex (which is not leak-checked), but StaticMutex can't
// be a member variable. So we have to have this separate variable and
// pass it into the NowSingleton constructor.
static mozilla::StaticMutex mutex MOZ_UNANNOTATED;
static NowSingleton now(mutex);
return now; return now;
} }
private: private:
explicit NowSingleton(mozilla::StaticMutex& aMutex) explicit NowSingleton()
: lock_(aMutex), : rollover_(TimeDelta::FromMilliseconds(0)), last_seen_(0) {}
rollover_(TimeDelta::FromMilliseconds(0)),
last_seen_(0) {}
~NowSingleton() = default; ~NowSingleton() = default;
mozilla::StaticMutex& lock_; // To protected last_seen_ and rollover_. TimeDelta rollover_ GUARDED_BY(
TimeDelta rollover_; // Accumulation of time lost due to rollover. sNowSingletonLock); // Accumulation of time lost due to rollover.
DWORD last_seen_; // The last timeGetTime value we saw, to detect rollover. DWORD last_seen_
GUARDED_BY(sNowSingletonLock); // The last timeGetTime value we saw, to
// detect rollover.
DISALLOW_COPY_AND_ASSIGN(NowSingleton); DISALLOW_COPY_AND_ASSIGN(NowSingleton);
}; };

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

@ -45,13 +45,13 @@ class BrowserProcessSubThread : public base::Thread {
// This lock protects |browser_threads_|. Do not read or modify that array // This lock protects |browser_threads_|. Do not read or modify that array
// without holding this lock. Do not block while holding this lock. // without holding this lock. Do not block while holding this lock.
static StaticMutex sLock MOZ_UNANNOTATED; static StaticMutex sLock;
// An array of the ChromeThread objects. This array is protected by |lock_|. // An array of the ChromeThread objects. This array is protected by |lock_|.
// The threads are not owned by this array. Typically, the threads are owned // The threads are not owned by this array. Typically, the threads are owned
// on the UI thread by the g_browser_process object. ChromeThreads remove // on the UI thread by the g_browser_process object. ChromeThreads remove
// themselves from this array upon destruction. // themselves from this array upon destruction.
static BrowserProcessSubThread* sBrowserThreads[ID_COUNT]; static BrowserProcessSubThread* sBrowserThreads[ID_COUNT] GUARDED_BY(sLock);
}; };
inline void AssertIOThread() { inline void AssertIOThread() {

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

@ -40,8 +40,8 @@ class CrashReporterClient {
~CrashReporterClient(); ~CrashReporterClient();
private: private:
static StaticMutex sLock MOZ_UNANNOTATED; static StaticMutex sLock;
static StaticRefPtr<CrashReporterClient> sClientSingleton; static StaticRefPtr<CrashReporterClient> sClientSingleton GUARDED_BY(sLock);
}; };
} // namespace ipc } // namespace ipc

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

@ -881,8 +881,9 @@ void BaseProcessLauncher::GetChildLogName(const char* origLogName,
#if defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID) || \ #if defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID) || \
defined(MOZ_ENABLE_FORKSERVER) defined(MOZ_ENABLE_FORKSERVER)
static mozilla::StaticMutex gIPCLaunchThreadMutex MOZ_UNANNOTATED; static mozilla::StaticMutex gIPCLaunchThreadMutex;
static mozilla::StaticRefPtr<nsIThread> gIPCLaunchThread; static mozilla::StaticRefPtr<nsIThread> gIPCLaunchThread
GUARDED_BY(gIPCLaunchThreadMutex);
class IPCLaunchThreadObserver final : public nsIObserver { class IPCLaunchThreadObserver final : public nsIObserver {
public: public:

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

@ -189,7 +189,7 @@ class GeckoChildProcessHost : public ChildProcessHost,
~GeckoChildProcessHost(); ~GeckoChildProcessHost();
GeckoProcessType mProcessType; GeckoProcessType mProcessType;
bool mIsFileContent; bool mIsFileContent;
Monitor mMonitor MOZ_UNANNOTATED; Monitor mMonitor;
FilePath mProcessPath; FilePath mProcessPath;
// GeckoChildProcessHost holds the launch options so they can be set // GeckoChildProcessHost holds the launch options so they can be set
// up on the main thread using main-thread-only APIs like prefs, and // up on the main thread using main-thread-only APIs like prefs, and
@ -215,7 +215,7 @@ class GeckoChildProcessHost : public ChildProcessHost,
// is well. // is well.
PROCESS_CONNECTED, PROCESS_CONNECTED,
PROCESS_ERROR PROCESS_ERROR
} mProcessState; } mProcessState GUARDED_BY(mMonitor);
void PrepareLaunch(); void PrepareLaunch();
@ -286,8 +286,8 @@ class GeckoChildProcessHost : public ChildProcessHost,
static uint32_t sNextUniqueID; static uint32_t sNextUniqueID;
static StaticAutoPtr<LinkedList<GeckoChildProcessHost>> static StaticAutoPtr<LinkedList<GeckoChildProcessHost>>
sGeckoChildProcessHosts; sGeckoChildProcessHosts GUARDED_BY(sMutex);
static StaticMutex sMutex MOZ_UNANNOTATED; static StaticMutex sMutex;
}; };
nsCOMPtr<nsIEventTarget> GetIPCLauncher(); nsCOMPtr<nsIEventTarget> GetIPCLauncher();

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

@ -133,8 +133,8 @@ class MessagePumpForNonMainUIThreads final : public base::MessagePumpForUI,
private: private:
~MessagePumpForNonMainUIThreads() {} ~MessagePumpForNonMainUIThreads() {}
bool mInWait; bool mInWait GUARDED_BY(mWaitLock);
mozilla::Mutex mWaitLock MOZ_UNANNOTATED; mozilla::Mutex mWaitLock;
}; };
#endif // defined(XP_WIN) #endif // defined(XP_WIN)