aboutsummaryrefslogtreecommitdiffstats
path: root/common/ringbuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/ringbuffer.cpp')
-rw-r--r--common/ringbuffer.cpp20
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;