diff options
author | Chris Robinson <[email protected]> | 2020-01-14 10:17:57 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-01-14 10:17:57 -0800 |
commit | 400c768e2fa5ea7ce72f2c4235f2363012153ac9 (patch) | |
tree | 7d9b84f563606ffd4bdad07aafdb2ff9f9e93b81 /alc/ringbuffer.h | |
parent | e889282131a8d6bb4dd8efea6b4e1f65fe38f0f4 (diff) |
Inline a couple ring buffer methods
Diffstat (limited to 'alc/ringbuffer.h')
-rw-r--r-- | alc/ringbuffer.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/alc/ringbuffer.h b/alc/ringbuffer.h index 78bea846..32fb951c 100644 --- a/alc/ringbuffer.h +++ b/alc/ringbuffer.h @@ -57,7 +57,13 @@ public: * Return the number of elements available for reading. This is the number * of elements in front of the read pointer and behind the write pointer. */ - size_t readSpace() const noexcept; + size_t readSpace() const noexcept + { + const size_t w{mWritePtr.load(std::memory_order_acquire)}; + const size_t r{mReadPtr.load(std::memory_order_acquire)}; + return (w-r) & mSizeMask; + } + /** * The copying data reader. Copy at most `cnt' elements into `dest'. * Returns the actual number of elements copied. @@ -75,7 +81,13 @@ public: * Return the number of elements available for writing. This is the number * of elements in front of the write pointer and behind the read pointer. */ - size_t writeSpace() const noexcept; + size_t writeSpace() const noexcept + { + const size_t w{mWritePtr.load(std::memory_order_acquire)}; + const size_t r{mReadPtr.load(std::memory_order_acquire) + mWriteSize - mSizeMask}; + return (r-w-1) & mSizeMask; + } + /** * The copying data writer. Copy at most `cnt' elements from `src'. Returns * the actual number of elements copied. |