diff options
author | Sven Göthel <[email protected]> | 2024-01-05 13:52:12 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-01-05 13:52:12 +0100 |
commit | ec98cdacc85ff0202852472c7756586437912f22 (patch) | |
tree | 42414746a27ab35cb8cdbc95af521d74821e57f4 /common/ringbuffer.cpp | |
parent | fd5269bec9a5fe4815974b1786a037e6a247bfd2 (diff) | |
parent | b82cd2e60edb8fbe5fdd3567105ae76a016a554c (diff) |
Diffstat (limited to 'common/ringbuffer.cpp')
-rw-r--r-- | common/ringbuffer.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/common/ringbuffer.cpp b/common/ringbuffer.cpp index af1f3669..2636bfb4 100644 --- a/common/ringbuffer.cpp +++ b/common/ringbuffer.cpp @@ -24,6 +24,8 @@ #include <algorithm> #include <climits> +#include <cstdint> +#include <limits> #include <stdexcept> #include "almalloc.h" @@ -40,7 +42,7 @@ RingBufferPtr RingBuffer::Create(std::size_t sz, std::size_t elem_sz, int limit_ power_of_two |= power_of_two>>4; power_of_two |= power_of_two>>8; power_of_two |= power_of_two>>16; - if constexpr(SIZE_MAX > UINT_MAX) + if constexpr(sizeof(size_t) > sizeof(uint32_t)) power_of_two |= power_of_two>>32; } ++power_of_two; @@ -159,7 +161,7 @@ std::size_t RingBuffer::write(const void *src, std::size_t cnt) noexcept } -auto RingBuffer::getReadVector() const noexcept -> DataPair +auto RingBuffer::getReadVector() noexcept -> DataPair { DataPair ret; @@ -174,15 +176,15 @@ auto RingBuffer::getReadVector() const noexcept -> DataPair { /* Two part vector: the rest of the buffer after the current read ptr, * plus some from the start of the buffer. */ - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + r*mElemSize); + ret.first.buf = mBuffer.data() + r*mElemSize; ret.first.len = mSizeMask+1 - r; - ret.second.buf = const_cast<std::byte*>(mBuffer.data()); + ret.second.buf = mBuffer.data(); ret.second.len = cnt2 & mSizeMask; } else { /* Single part vector: just the rest of the buffer */ - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + r*mElemSize); + ret.first.buf = mBuffer.data() + r*mElemSize; ret.first.len = free_cnt; ret.second.buf = nullptr; ret.second.len = 0; @@ -191,7 +193,7 @@ auto RingBuffer::getReadVector() const noexcept -> DataPair return ret; } -auto RingBuffer::getWriteVector() const noexcept -> DataPair +auto RingBuffer::getWriteVector() noexcept -> DataPair { DataPair ret; @@ -206,14 +208,14 @@ auto RingBuffer::getWriteVector() const noexcept -> DataPair { /* Two part vector: the rest of the buffer after the current write ptr, * plus some from the start of the buffer. */ - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + w*mElemSize); + ret.first.buf = mBuffer.data() + w*mElemSize; ret.first.len = mSizeMask+1 - w; - ret.second.buf = const_cast<std::byte*>(mBuffer.data()); + ret.second.buf = mBuffer.data(); ret.second.len = cnt2 & mSizeMask; } else { - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + w*mElemSize); + ret.first.buf = mBuffer.data() + w*mElemSize; ret.first.len = free_cnt; ret.second.buf = nullptr; ret.second.len = 0; |