Skip to content

Commit db64356

Browse files
committed
Futher enhancements to circular_queue from EspSoftwareSerial.
1 parent 725b6c9 commit db64356

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libraries/FastScheduler/src/circular_queue/circular_queue.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class circular_queue
186186

187187
/*!
188188
@brief Pop multiple elements in ordered sequence from the queue to a buffer.
189+
If buffer is nullptr, simply discards up to size elements from the queue.
189190
@return The number of elements actually popped from the queue to
190191
buffer.
191192
*/
@@ -313,9 +314,11 @@ size_t circular_queue<T>::pop_n(T* buffer, size_t size) {
313314

314315
std::atomic_thread_fence(std::memory_order_acquire);
315316

316-
buffer = std::copy_n(std::make_move_iterator(m_buffer.get() + outPos), n, buffer);
317-
avail -= n;
318-
std::copy_n(std::make_move_iterator(m_buffer.get()), avail, buffer);
317+
if (buffer) {
318+
buffer = std::copy_n(std::make_move_iterator(m_buffer.get() + outPos), n, buffer);
319+
avail -= n;
320+
std::copy_n(std::make_move_iterator(m_buffer.get()), avail, buffer);
321+
}
319322

320323
std::atomic_thread_fence(std::memory_order_release);
321324

0 commit comments

Comments
 (0)