Bug 1765242 - Rename IOInterposer.cpp's thread-safe list of observers to SourceList - r=dthayer

Differential Revision: https://phabricator.services.mozilla.com/D143975
This commit is contained in:
Gerald Squelart 2022-04-19 20:39:38 +00:00
parent 9a0eaa2c22
commit 9c53f3da99

View file

@ -154,15 +154,17 @@ class PerThreadData {
RefPtr<ObserverLists> mObserverLists; RefPtr<ObserverLists> mObserverLists;
}; };
class MasterList { // Thread-safe list of observers, from which `PerThreadData` sources its own
// local list when needed.
class SourceList {
public: public:
MasterList() SourceList()
: mObservedOperations(mozilla::IOInterposeObserver::OpNone), : mObservedOperations(mozilla::IOInterposeObserver::OpNone),
mIsEnabled(true) { mIsEnabled(true) {
MOZ_COUNT_CTOR(MasterList); MOZ_COUNT_CTOR(SourceList);
} }
MOZ_COUNTED_DTOR(MasterList) MOZ_COUNTED_DTOR(SourceList)
inline void Disable() { mIsEnabled = false; } inline void Disable() { mIsEnabled = false; }
inline void Enable() { mIsEnabled = true; } inline void Enable() { mIsEnabled = true; }
@ -284,7 +286,7 @@ class MasterList {
return; return;
} }
// If the generation counts don't match then we need to update the current // If the generation counts don't match then we need to update the current
// thread's observer list with the new master list. // thread's observer list with the new source list.
mozilla::IOInterposer::AutoLock lock(mLock); mozilla::IOInterposer::AutoLock lock(mLock);
aPtd.SetObserverLists(mCurrentGeneration, mObserverLists); aPtd.SetObserverLists(mCurrentGeneration, mObserverLists);
} }
@ -311,7 +313,7 @@ class MasterList {
mObservedOperations; mObservedOperations;
// Used for quickly disabling everything by IOInterposer::Disable() // Used for quickly disabling everything by IOInterposer::Disable()
mozilla::Atomic<bool> mIsEnabled; mozilla::Atomic<bool> mIsEnabled;
// Used to inform threads that the master observer list has changed // Used to inform threads that the source observer list has changed
mozilla::Atomic<uint32_t> mCurrentGeneration; mozilla::Atomic<uint32_t> mCurrentGeneration;
}; };
@ -327,7 +329,7 @@ class NextStageObservation : public mozilla::IOInterposeObserver::Observation {
}; };
// List of observers registered // List of observers registered
static mozilla::StaticAutoPtr<MasterList> sMasterList; static mozilla::StaticAutoPtr<SourceList> sSourceList;
static MOZ_THREAD_LOCAL(PerThreadData*) sThreadLocalData; static MOZ_THREAD_LOCAL(PerThreadData*) sThreadLocalData;
static bool sThreadLocalDataInitialized; static bool sThreadLocalDataInitialized;
@ -387,7 +389,7 @@ void IOInterposeObserver::Observation::Report() {
bool IOInterposer::Init() { bool IOInterposer::Init() {
// Don't initialize twice... // Don't initialize twice...
if (sMasterList) { if (sSourceList) {
return true; return true;
} }
if (!sThreadLocalData.init()) { if (!sThreadLocalData.init()) {
@ -396,7 +398,7 @@ bool IOInterposer::Init() {
sThreadLocalDataInitialized = true; sThreadLocalDataInitialized = true;
bool isMainThread = true; bool isMainThread = true;
RegisterCurrentThread(isMainThread); RegisterCurrentThread(isMainThread);
sMasterList = new MasterList(); sSourceList = new SourceList();
MainThreadIOLogger::Init(); MainThreadIOLogger::Init();
@ -434,22 +436,22 @@ void IOInterposer::Clear() {
IOInterposer so that all references are properly released. */ IOInterposer so that all references are properly released. */
#ifdef NS_FREE_PERMANENT_DATA #ifdef NS_FREE_PERMANENT_DATA
UnregisterCurrentThread(); UnregisterCurrentThread();
sMasterList = nullptr; sSourceList = nullptr;
#endif #endif
} }
void IOInterposer::Disable() { void IOInterposer::Disable() {
if (!sMasterList) { if (!sSourceList) {
return; return;
} }
sMasterList->Disable(); sSourceList->Disable();
} }
void IOInterposer::Enable() { void IOInterposer::Enable() {
if (!sMasterList) { if (!sSourceList) {
return; return;
} }
sMasterList->Enable(); sSourceList->Enable();
} }
void IOInterposer::Report(IOInterposeObserver::Observation& aObservation) { void IOInterposer::Report(IOInterposeObserver::Observation& aObservation) {
@ -461,13 +463,13 @@ void IOInterposer::Report(IOInterposeObserver::Observation& aObservation) {
return; return;
} }
if (!sMasterList) { if (!sSourceList) {
// If there is no longer a master list then we should clear the local one. // If there is no longer a source list then we should clear the local one.
ptd->ClearObserverLists(); ptd->ClearObserverLists();
return; return;
} }
sMasterList->Update(*ptd); sSourceList->Update(*ptd);
// Don't try to report if there's nobody listening. // Don't try to report if there's nobody listening.
if (!IOInterposer::IsObservedOperation(aObservation.ObservedOperation())) { if (!IOInterposer::IsObservedOperation(aObservation.ObservedOperation())) {
@ -478,26 +480,26 @@ void IOInterposer::Report(IOInterposeObserver::Observation& aObservation) {
} }
bool IOInterposer::IsObservedOperation(IOInterposeObserver::Operation aOp) { bool IOInterposer::IsObservedOperation(IOInterposeObserver::Operation aOp) {
return sMasterList && sMasterList->IsObservedOperation(aOp); return sSourceList && sSourceList->IsObservedOperation(aOp);
} }
void IOInterposer::Register(IOInterposeObserver::Operation aOp, void IOInterposer::Register(IOInterposeObserver::Operation aOp,
IOInterposeObserver* aObserver) { IOInterposeObserver* aObserver) {
MOZ_ASSERT(aObserver); MOZ_ASSERT(aObserver);
if (!sMasterList || !aObserver) { if (!sSourceList || !aObserver) {
return; return;
} }
sMasterList->Register(aOp, aObserver); sSourceList->Register(aOp, aObserver);
} }
void IOInterposer::Unregister(IOInterposeObserver::Operation aOp, void IOInterposer::Unregister(IOInterposeObserver::Operation aOp,
IOInterposeObserver* aObserver) { IOInterposeObserver* aObserver) {
if (!sMasterList) { if (!sSourceList) {
return; return;
} }
sMasterList->Unregister(aOp, aObserver); sSourceList->Unregister(aOp, aObserver);
} }
void IOInterposer::RegisterCurrentThread(bool aIsMainThread) { void IOInterposer::RegisterCurrentThread(bool aIsMainThread) {
@ -520,7 +522,7 @@ void IOInterposer::UnregisterCurrentThread() {
} }
void IOInterposer::EnteringNextStage() { void IOInterposer::EnteringNextStage() {
if (!sMasterList) { if (!sSourceList) {
return; return;
} }
NextStageObservation observation; NextStageObservation observation;