gecko-dev/mfbt
Andreas Pehrson 76a7426f90 Bug 1844181 - Add memory synchronization to SPSCQueue's thread id reset methods. r=decoder,padenot,handyman
Without this, the necessary synchronization must be provided externally.

This fixes the memory order in the following case of changing producer thread:
- Thread A does SPSCQueue::Enqueue
  - non-atomic write into the ring buffer, at memory location X
  - mWriteIndex.load(relaxed)
  - mWriteIndex.store(release)
- Producer thread is switched to B, no external memory order synchronization is
  provided, but thread B is guaranteed to run after thread A has finished its
  Enqueue task.
- Thread B does SPSCQueue::Enqueue
  - mWriteIndex.load(relaxed)
  - mWriteIndex.store(release)
- Thread C does SPSCQueue::Dequeue
  - mWriteIndex.load(acquire)
  - non-atomic read from the ring buffer, at memory location X

In this scenario, there is no memory synchronization between threads A and B,
and therefore the non-atomic read on C is a data race, and flagged as such by
TSAN.

A similar scenario can be applied to changing the consumer thread, if first A
enqueues, then B dequeues, then C dequeues. However, since Dequeue doesn't
necessarily (MoveOrCopy) do non-atomic writes to the ring buffer, and more
importantly, since Enqueue doesn't do non-atomic reads from the ring buffer,
this is less of a problem.

Differential Revision: https://phabricator.services.mozilla.com/D190084
2023-10-09 13:02:58 +00:00
..
double-conversion Bug 1844554 - Vendor double-conversion using `mach vendor` r=RyanVM 2023-07-21 08:12:09 +00:00
lz4 Bug 1845018 - Update xxHash to version 0.8.2. r=dthayer 2023-07-26 16:21:11 +00:00
tests Bug 1844181 - Add memory synchronization to SPSCQueue's thread id reset methods. r=decoder,padenot,handyman 2023-10-09 13:02:58 +00:00
Algorithm.h Bug 1677092: add `constexpr` `AnyOf`. r=sg 2020-11-17 08:30:12 +00:00
Alignment.h
AllocPolicy.h Bug 1571631 - Replace MOZ_MUST_USE with [[nodiscard]] in mfbt. r=sg 2021-03-17 03:01:21 +00:00
AlreadyAddRefed.h Bug 1856746: Extend already_AddRefed documentation to mention a case where it makes sense as a function parameter. r=nika 2023-10-04 18:49:03 +00:00
Array.h Bug 1733963 - Part 1: Make BitSet work as storage for EnumSet. r=glandium 2021-11-09 12:34:51 +00:00
ArrayUtils.h Bug 1678062 - Remove unnecessary includes. r=andi 2020-11-23 16:12:02 +00:00
Assertions.cpp Bug 1624717 - Copy release mode bounds checking from nsTArray to Array r=glandium 2021-09-09 13:29:18 +00:00
Assertions.h Bug 1838828 - Fix obsolete comment in Assertions.h: MOZ_RELEASE_ASSERT is no-op only in late beta and release. r=chunmin 2023-07-07 00:51:27 +00:00
AtomicBitfields.h Bug 1701879 part 5 - Add stub atomics implementation for WASI. r=wingo,glandium 2021-04-20 05:15:28 +00:00
Atomics.h Bug 1701879 part 5 - Add stub atomics implementation for WASI. r=wingo,glandium 2021-04-20 05:15:28 +00:00
Attributes.h Bug 1829425 - Rename the ASAN/TSAN blacklist macros. r=decoder 2023-04-24 12:47:00 +00:00
BinarySearch.h Bug 1843181 - Make EqualRange return a std::pair. r=sergesanspaille 2023-07-14 21:51:27 +00:00
BitSet.h Bug 1768632: Make EnumSet compile for MSVC. r=glandium 2022-08-17 06:39:12 +00:00
BloomFilter.h Bug 1828560 - Part 2: Rename BitBloomFilter::mCounters to mBits. r=dpalmeiro 2023-04-19 05:25:09 +00:00
Buffer.h Bug 1678062 - Remove unnecessary includes. r=andi 2020-11-23 16:12:02 +00:00
BufferList.h Bug 1783242 - Part 3: Remove BufferList::Extract, r=glandium,ipc-reviewers,mccr8 2022-09-28 19:25:14 +00:00
Casting.h Bug 1812353 - Update GPUSupportedLimits in webgpu.webidl. r=webgpu-reviewers,webidl,saschanaz,jimb,emilio,smaug 2023-06-12 21:10:11 +00:00
ChaosMode.cpp
ChaosMode.h
Char16.h Bug 1766549 - Remove some char16ptr_t operators that allow implicit const-casting. r=nika 2022-04-27 22:28:24 +00:00
CheckedInt.h Bug 1743012 - Add missing `constexpr` qualifiers in `CheckedInt`, r=glandium 2021-11-26 19:18:49 +00:00
CompactPair.h Bug 1601556 - Make Result<V, E> a literal type if V and E are literal types and PackingStrategy is not Variant. r=emilio 2021-03-23 12:35:19 +00:00
Compiler.h
Compression.cpp
Compression.h Bug 1571631 - Replace MOZ_MUST_USE with [[nodiscard]] in mfbt. r=sg 2021-03-17 03:01:21 +00:00
DbgMacro.h
DebugOnly.h Bug 1664844 - Add DebugOnly::inspect member function. r=jwalden 2020-09-18 06:33:12 +00:00
DefineEnum.h
DoublyLinkedList.h Bug 1777925: Replaced MutationObserver array container type with linked list. r=smaug 2022-09-21 11:31:44 +00:00
EndianUtils.h Bug 1571631 - Replace MOZ_MUST_USE with [[nodiscard]] in mfbt. r=sg 2021-03-17 03:01:21 +00:00
EnumSet.h Bug 1768632: Make EnumSet compile for MSVC. r=glandium 2022-08-17 06:39:12 +00:00
EnumTypeTraits.h
EnumeratedArray.h
EnumeratedRange.h Bug 1812353 - Update GPUSupportedLimits in webgpu.webidl. r=webgpu-reviewers,webidl,saschanaz,jimb,emilio,smaug 2023-06-12 21:10:11 +00:00
FStream.h
FastBernoulliTrial.h
FloatingPoint.cpp Bug 1660405 - Move away from mozilla::IsFinite in favor of std::isfinite. r=sergesanspaille 2023-03-22 11:35:33 +00:00
FloatingPoint.h Bug 1660405 - Transform mozilla::IsNegative to use std implementation. r=glandium 2023-03-22 11:35:36 +00:00
FunctionRef.h
FunctionTypeTraits.h Bug 1277372 - Remove unused "mozilla/TypeTraits.h" r=sergesanspaille 2023-04-17 13:50:11 +00:00
Fuzzing.h Bug 1821008 - Add nyx abort macro and more debug messages. r=truber,glandium 2023-03-14 07:50:36 +00:00
HashFunctions.cpp Bug 1719396: Don't hash sizeof(size_t) in HashBytes r=glandium 2021-07-19 21:35:40 +00:00
HashFunctions.h Bug 1341265 - Part 11: Optimise Set.prototype.has for objects in CacheIR. r=iain 2021-08-10 09:55:22 +00:00
HashTable.h Bug 1849386 - Use consistent pointer hashing. r=nika,xpcom-reviewers 2023-08-18 22:35:40 +00:00
HelperMacros.h
InitializedOnce.h Bug 1685679 - Add do_Init function to allow assignment to InitializedOnce variables. r=janv 2021-01-15 11:23:41 +00:00
IntegerRange.h
IntegerTypeTraits.h Bug 1277372 - Remove unused "mozilla/TypeTraits.h" r=sergesanspaille 2023-04-17 13:50:11 +00:00
JSONWriter.cpp
JSONWriter.h Bug 1784812 - JSONWriter may optionally not own its writer - r=canaltinova 2022-08-17 07:07:53 +00:00
JsRust.h
Latin1.h Bug 1276351 - Move away from mozilla::tuple to std::tuple. r=necko-reviewers,sergesanspaille 2023-03-27 07:20:25 +00:00
Likely.h
LinkedList.h Bug 1750791 - Part 1: Add LinkedList::mergeBack and LinkedList::splice. r=glandium 2022-02-24 15:00:27 +00:00
MacroArgs.h Bug 1666219 - Introduce QM_TRY_INSPECT to avoid unwrapping Result objects where not necessary. r=dom-workers-and-storage-reviewers,janv 2020-09-29 10:57:14 +00:00
MacroForEach.h
MathAlgorithms.h Bug 1821362 - Replace EuclidGCD by a binary gcd algorithm using intrinsics. r=media-playback-reviewers,alwu 2023-05-24 13:18:41 +00:00
Maybe.h Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
MaybeOneOf.h Bug 1766276 - Give MaybeOneOf a map method r=jandem 2022-04-26 12:29:24 +00:00
MaybeStorageBase.h Bug 1700336 - Use MaybeStorageBase in Maybe. r=emilio 2021-03-24 13:21:31 +00:00
MemoryChecking.h
MemoryReporting.h
MoveOnlyFunction.h Bug 1743020 - Part 3: Export mozilla::MoveOnlyFunction based on function2, r=glandium 2022-06-02 13:24:10 +00:00
MruCache.h Bug 1815396 - Fix documentation of MruCache. r=lsalzman 2023-03-06 10:43:27 +00:00
NeverDestroyed.h Bug 1851045 - Part 4: Add a NeverDestroyed helper type to MFBT for static local members, r=glandium 2023-09-27 19:14:16 +00:00
NonDereferenceable.h
NotNull.h Bug 1607634 - Part 1: Improve the ergonomics of using NotNull with RefPtr and nsCOMPtr, r=glandium 2023-03-20 15:40:35 +00:00
Opaque.h
OperatorNewExtensions.h
PairHash.h Bug 1571631 - Replace MOZ_MUST_USE with [[nodiscard]] in mfbt. r=sg 2021-03-17 03:01:21 +00:00
Path.h
PodOperations.h Bug 1678062 - Remove unnecessary includes. r=andi 2020-11-23 16:12:02 +00:00
Poison.cpp Bug 1701620 part 4 - Fix memory support for WASI. r=jandem,sfink 2021-04-13 08:25:10 +00:00
Poison.h Bug 1506910 - Initialize the poison page with a static initializer. r=glandium,decoder 2020-10-28 20:38:42 +00:00
RandomNum.cpp Bug 1816953 - Stop hooking BCryptGenRandom. r=cmartin,handyman 2023-05-03 13:40:36 +00:00
RandomNum.h Bug 1723674 - mfbt: Add new GenerateRandomBytes() function. r=cmartin 2021-10-14 03:28:48 +00:00
Range.h
RangedArray.h
RangedPtr.h
ReentrancyGuard.h
RefCountType.h
RefCounted.h Bug 1843568 - Part 3: Annotate `nsIEventTarget` as rust_sync, r=xpcom-reviewers,barret 2023-07-20 17:39:03 +00:00
RefPtr.h Bug 1607634 - Part 1: Improve the ergonomics of using NotNull with RefPtr and nsCOMPtr, r=glandium 2023-03-20 15:40:35 +00:00
Result.h Bug 1855134 - Move existing MOZ_TRY macros to a dedicated header file; r=glandium 2023-09-28 20:46:07 +00:00
ResultExtensions.h Bug 1732642 - Handle complex types in MOZ_TO_RESULT_INVOKE_MEMBER_TYPED; r=dom-storage-reviewers,jari 2021-11-30 05:05:53 +00:00
ResultVariant.h Bug 1769518 - Support Rooted<Result<V,E>> as long as V and E have GCPolicy<> defined for them. (Use IgnoreGCPolicy for whichever of them does not need tracing.) r=emilio,nbp,jonco 2022-05-26 17:22:35 +00:00
ReverseIterator.h
RollingMean.h Bug 1666487 - Constify some RollingMean getters. r=glandium 2021-02-11 13:38:48 +00:00
SHA1.cpp Bug 1806779 - Fix C++20 -Wdeprecated-volatile warnings in mfbt/SHA1.cpp. r=glandium 2022-12-22 02:58:24 +00:00
SHA1.h
SPSCQueue.h Bug 1844181 - Add memory synchronization to SPSCQueue's thread id reset methods. r=decoder,padenot,handyman 2023-10-09 13:02:58 +00:00
STYLE
Saturate.h
ScopeExit.h Bug 1725572 - Part 1: Support move-only closures in ScopeExit, r=glandium 2021-09-23 18:54:31 +00:00
Scoped.h
SegmentedVector.h Bug 1730534 - Part 1: Assert state of SegmentedVector iterator is valid r=mccr8 2021-09-27 16:41:51 +00:00
SharedLibrary.h
SmallPointerArray.h Bug 1678062 - Remove unnecessary includes. r=andi 2020-11-23 16:12:02 +00:00
Span.h Bug 1841314 - Part 3: Prefer JS::NewArrayBufferWithContents with UniquePtr. r=sfink,saschanaz 2023-07-06 20:50:59 +00:00
SplayTree.h
StaticAnalysisFunctions.h Bug 1699844 - Add an escape hatch for the refcounted inside lambda checker. r=andi 2021-04-14 19:12:02 +00:00
TaggedAnonymousMemory.cpp
TaggedAnonymousMemory.h Bug 1701620 part 4 - Fix memory support for WASI. r=jandem,sfink 2021-04-13 08:25:10 +00:00
Tainting.h Bug 1811645 - avoid an American English colloquialism meaning "nonsense" r=Gijs 2023-04-20 22:24:00 +00:00
TemplateLib.h Bug 1679492 - Remove parts that are unused from mfbt/TemplateLib. r=sergesanspaille 2023-04-18 12:42:13 +00:00
TextUtils.h Bug 1795644 - A bit of tuning of inlining in the JS parser. r=arai. 2022-10-18 05:22:03 +00:00
ThreadLocal.h Bug 1701613 part 3 - Add stub thread implementation for WASI. r=jandem,wingo 2021-04-08 08:02:16 +00:00
ThreadSafeWeakPtr.h Bug 1843568 - Part 3: Annotate `nsIEventTarget` as rust_sync, r=xpcom-reviewers,barret 2023-07-20 17:39:03 +00:00
ThreadSafety.h Bug 1854305 - Don't enable thread safety annotations before clang 11. r=nika 2023-09-21 20:42:33 +00:00
ToString.h
Try.h Bug 1855134 - Move existing MOZ_TRY macros to a dedicated header file; r=glandium 2023-09-28 20:46:07 +00:00
TsanOptions.h Bug 1824768 - Add TSan suppressions for external libs. r=decoder 2023-07-07 10:12:54 +00:00
TypedEnumBits.h
Types.h
UniquePtr.h Bug 1782604 - Make UniquePtr(nullptr) constexpr r=glandium 2022-08-03 21:21:09 +00:00
UniquePtrExtensions.cpp
UniquePtrExtensions.h Bug 1834912 - Add iOS-related defines/ifdefs for IPC. r=ipc-reviewers,nika 2023-05-25 02:48:33 +00:00
Unused.cpp
Unused.h
Utf8.cpp
Utf8.h Bug 1276351 - Move away from mozilla::tuple to std::tuple. r=necko-reviewers,sergesanspaille 2023-03-27 07:20:25 +00:00
Variant.h Bug 1719959 - Better Tag type choice, fixed corresponding test - r=emilio 2021-07-11 09:43:50 +00:00
Vector.h Bug 1828784 - Work around VS 2019+ SDK issue. r=glandium 2023-04-19 22:51:46 +00:00
WasiAtomic.h Bug 1758780 - Fallthrough to <atomic> for wasi when using clang >= 14. r=nika 2022-04-13 03:02:24 +00:00
WeakPtr.h Bug 1672072 - P12. Add constructor for WeakPtr(RefPtr). r=sg 2020-11-13 04:21:17 +00:00
WindowsVersion.h Bug 1777960 - Patch msctf.dll to prevent a crash with ZoneAlarm Anti-Keylogger. r=gstoll,win-reviewers 2023-10-03 15:24:47 +00:00
WrappingOperations.h
XorShift128PlusRNG.h
fallible.h Bug 1668421 - Fix a commeint in fallible.h r=glandium 2020-10-05 00:50:31 +00:00
moz.build Bug 1855134 - Move existing MOZ_TRY macros to a dedicated header file; r=glandium 2023-09-28 20:46:07 +00:00