mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1752345 - Allow calling AvailableWrite or AvailableRead on any thread. r=alwu
This is safe in fact safe. The data might be a bit late, but it's going to be correct. Differential Revision: https://phabricator.services.mozilla.com/D137302
This commit is contained in:
parent
05e420b119
commit
f0f4d715ec
@ -225,18 +225,14 @@ class SPSCRingBufferBase {
|
||||
/**
|
||||
* Get the number of available elements for consuming.
|
||||
*
|
||||
* Only safely called on the consumer thread. This can be less than the actual
|
||||
* number of elements in the queue, since the mWriteIndex is updated at the
|
||||
* very end of the Enqueue method on the producer thread, but consequently
|
||||
* always returns a number of elements such that a call to Dequeue return this
|
||||
* number of elements.
|
||||
* This can be less than the actual number of elements in the queue, since the
|
||||
* mWriteIndex is updated at the very end of the Enqueue method on the
|
||||
* producer thread, but consequently always returns a number of elements such
|
||||
* that a call to Dequeue return this number of elements.
|
||||
*
|
||||
* @return The number of available elements for reading.
|
||||
*/
|
||||
int AvailableRead() const {
|
||||
#ifdef DEBUG
|
||||
AssertCorrectThread(mConsumerId);
|
||||
#endif
|
||||
return AvailableReadInternal(
|
||||
mReadIndex.load(std::memory_order::memory_order_relaxed),
|
||||
mWriteIndex.load(std::memory_order::memory_order_relaxed));
|
||||
@ -244,18 +240,14 @@ class SPSCRingBufferBase {
|
||||
/**
|
||||
* Get the number of available elements for writing.
|
||||
*
|
||||
* Only safely called on the producer thread. This can be less than than the
|
||||
* actual number of slots that are available, because mReadIndex is update at
|
||||
* the very end of the Deque method. It always returns a number such that a
|
||||
* call to Enqueue with this number will succeed in enqueuing this number of
|
||||
* elements.
|
||||
* This can be less than than the actual number of slots that are available,
|
||||
* because mReadIndex is updated at the very end of the Deque method. It
|
||||
* always returns a number such that a call to Enqueue with this number will
|
||||
* succeed in enqueuing this number of elements.
|
||||
*
|
||||
* @return The number of empty slots in the buffer, available for writing.
|
||||
*/
|
||||
int AvailableWrite() const {
|
||||
#ifdef DEBUG
|
||||
AssertCorrectThread(mProducerId);
|
||||
#endif
|
||||
return AvailableWriteInternal(
|
||||
mReadIndex.load(std::memory_order::memory_order_relaxed),
|
||||
mWriteIndex.load(std::memory_order::memory_order_relaxed));
|
||||
|
Loading…
Reference in New Issue
Block a user