Bug 1630655 - Squash TSAN data race report in IOInterposer r=aklotz

In practice this shouldn't substantially change the behavior, but
it gets around being UB, and it shouldn't really cost us in terms
of performance. The alternative would be adding it to the TSAN
whitelist, which feels worse.

Differential Revision: https://phabricator.services.mozilla.com/D72015
This commit is contained in:
Doug Thayer 2020-04-24 20:31:53 +00:00
parent 686c7cce17
commit dfa7ab6aeb

View File

@ -290,11 +290,10 @@ class MasterList {
}
inline bool IsObservedOperation(mozilla::IOInterposeObserver::Operation aOp) {
// The quick reader may observe that no locks are being employed here,
// hence the result of the operations is truly undefined. However, most
// computers will usually return either true or false, which is good enough.
// It is not a problem if we occasionally report more or less IO than is
// actually occurring.
// This does not occur inside of a lock, so this makes no guarantees that
// the observers are in sync with this. That is acceptable; it is not a
// problem if we occasionally report more or less IO than is actually
// occurring.
return mIsEnabled && !!(mObservedOperations & aOp);
}
@ -307,7 +306,9 @@ class MasterList {
// during shutdown.
mozilla::IOInterposer::Mutex mLock;
// Flags tracking which operations are being observed
mozilla::IOInterposeObserver::Operation mObservedOperations;
mozilla::Atomic<mozilla::IOInterposeObserver::Operation,
mozilla::MemoryOrdering::Relaxed>
mObservedOperations;
// Used for quickly disabling everything by IOInterposer::Disable()
mozilla::Atomic<bool> mIsEnabled;
// Used to inform threads that the master observer list has changed