util/CircularBuffer: use std::span

This commit is contained in:
Max Kellermann
2022-05-20 10:59:53 +02:00
parent b37c031fd1
commit b50173ae8b
6 changed files with 51 additions and 55 deletions

View File

@@ -240,7 +240,7 @@ AlsaInputStream::DispatchSockets() noexcept
const std::scoped_lock<Mutex> protect(mutex);
auto w = PrepareWriteBuffer();
const snd_pcm_uframes_t w_frames = w.size / frame_size;
const snd_pcm_uframes_t w_frames = w.size() / frame_size;
if (w_frames == 0) {
/* buffer is full */
Pause();
@@ -249,7 +249,7 @@ AlsaInputStream::DispatchSockets() noexcept
snd_pcm_sframes_t n_frames;
while ((n_frames = snd_pcm_readi(capture_handle,
w.data, w_frames)) < 0) {
w.data(), w_frames)) < 0) {
if (n_frames == -EAGAIN)
return;

View File

@@ -123,7 +123,7 @@ UringInputStream::SubmitRead() noexcept
read_operation = std::make_unique<Uring::ReadOperation>();
read_operation->Start(uring, fd, next_offset,
std::min(w.size, URING_MAX_READ),
std::min(w.size(), URING_MAX_READ),
*this);
}
@@ -158,8 +158,8 @@ UringInputStream::OnRead(std::unique_ptr<std::byte[]> data,
}
auto w = PrepareWriteBuffer();
assert(w.size >= nbytes);
memcpy(w.data, data.get(), nbytes);
assert(w.size() >= nbytes);
memcpy(w.data(), data.get(), nbytes);
CommitWriteBuffer(nbytes);
next_offset += nbytes;
SubmitRead();