Skip to content

Commit 8a83678

Browse files
authored
fix: assert when serial server and terminal receive data queue is full (#802)
* fix: assert when serial server and terminal receive data queue is full * review comments resolved
1 parent ae01eea commit 8a83678

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

infra/event/QueueForOneReaderOneIrqWriter.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "infra/event/EventDispatcher.hpp"
55
#include "infra/stream/InputStream.hpp"
66
#include "infra/util/Function.hpp"
7+
#include "infra/util/ReallyAssert.hpp"
78
#include "infra/util/WithStorage.hpp"
89
#include <array>
910
#include <atomic>
@@ -26,7 +27,9 @@ namespace infra
2627
QueueForOneReaderOneIrqWriter(infra::MemoryRange<T> buffer, const infra::Function<void()>& onDataAvailable);
2728

2829
void AddFromInterrupt(T element);
30+
void AddFromInterruptUnchecked(T element);
2931
void AddFromInterrupt(infra::MemoryRange<const T> data);
32+
void AddFromInterruptUnchecked(infra::MemoryRange<const T> data);
3033

3134
bool Empty() const;
3235
bool Full() const;
@@ -89,7 +92,13 @@ namespace infra
8992
template<class T>
9093
void QueueForOneReaderOneIrqWriter<T>::AddFromInterrupt(T element)
9194
{
92-
assert(!Full());
95+
really_assert(!Full());
96+
AddFromInterruptUnchecked(element);
97+
}
98+
99+
template<class T>
100+
void QueueForOneReaderOneIrqWriter<T>::AddFromInterruptUnchecked(T element)
101+
{
93102
*contentsEnd = element;
94103

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

103112
template<class T>
104113
void QueueForOneReaderOneIrqWriter<T>::AddFromInterrupt(infra::MemoryRange<const T> data)
114+
{
115+
really_assert(!Full());
116+
AddFromInterruptUnchecked(data);
117+
}
118+
119+
template<class T>
120+
void QueueForOneReaderOneIrqWriter<T>::AddFromInterruptUnchecked(infra::MemoryRange<const T> data)
105121
{
106122
std::size_t copySize = std::min<std::size_t>(data.size(), buffer.end() - contentsEnd);
107123
T* begin = contentsBegin.load();

0 commit comments

Comments
 (0)