Bug 1830206 - Fix an overly restrictive assertion in the SPSC ringbuffer. r=alwu, a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D177770
This commit is contained in:
Paul Adenot 2023-05-24 13:11:46 +00:00
parent c841ed68f5
commit 71ce0dc50f

View File

@ -103,13 +103,11 @@ class SPSCRingBufferBase {
*/
explicit SPSCRingBufferBase(int aCapacity)
: mReadIndex(0),
mWriteIndex(0)
mWriteIndex(0),
/* One more element to distinguish from empty and full buffer. */
,
mCapacity(aCapacity + 1) {
MOZ_ASSERT(StorageCapacity() < std::numeric_limits<int>::max() / 2,
"buffer too large for the type of index used.");
MOZ_ASSERT(mCapacity > 0 && aCapacity != std::numeric_limits<int>::max());
MOZ_RELEASE_ASSERT(aCapacity != std::numeric_limits<int>::max());
MOZ_RELEASE_ASSERT(mCapacity > 0);
mData = std::make_unique<T[]>(StorageCapacity());