Skip to content

Commit

Permalink
fix: assert when serial server and terminal receive data queue is full (
Browse files Browse the repository at this point in the history
#802)

* fix: assert when serial server and terminal receive data queue is full

* review comments resolved
  • Loading branch information
magi-arun authored Jan 15, 2025
1 parent ae01eea commit 8a83678
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion infra/event/QueueForOneReaderOneIrqWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "infra/event/EventDispatcher.hpp"
#include "infra/stream/InputStream.hpp"
#include "infra/util/Function.hpp"
#include "infra/util/ReallyAssert.hpp"
#include "infra/util/WithStorage.hpp"
#include <array>
#include <atomic>
Expand All @@ -26,7 +27,9 @@ namespace infra
QueueForOneReaderOneIrqWriter(infra::MemoryRange<T> buffer, const infra::Function<void()>& onDataAvailable);

void AddFromInterrupt(T element);
void AddFromInterruptUnchecked(T element);
void AddFromInterrupt(infra::MemoryRange<const T> data);
void AddFromInterruptUnchecked(infra::MemoryRange<const T> data);

bool Empty() const;
bool Full() const;
Expand Down Expand Up @@ -89,7 +92,13 @@ namespace infra
template<class T>
void QueueForOneReaderOneIrqWriter<T>::AddFromInterrupt(T element)
{
assert(!Full());
really_assert(!Full());
AddFromInterruptUnchecked(element);
}

template<class T>
void QueueForOneReaderOneIrqWriter<T>::AddFromInterruptUnchecked(T element)
{
*contentsEnd = element;

if (contentsEnd == buffer.end() - 1)
Expand All @@ -102,6 +111,13 @@ namespace infra

template<class T>
void QueueForOneReaderOneIrqWriter<T>::AddFromInterrupt(infra::MemoryRange<const T> data)
{
really_assert(!Full());
AddFromInterruptUnchecked(data);
}

template<class T>
void QueueForOneReaderOneIrqWriter<T>::AddFromInterruptUnchecked(infra::MemoryRange<const T> data)
{
std::size_t copySize = std::min<std::size_t>(data.size(), buffer.end() - contentsEnd);
T* begin = contentsBegin.load();
Expand Down

0 comments on commit 8a83678

Please sign in to comment.