From b53e14c7f8709fddecd365c191ceb7f4f2ac4fdd Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 28 Aug 2024 00:42:11 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Guard=20que?= =?UTF-8?q?ue=20advance=5Fr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/gcode/queue.cpp | 4 ++-- Marlin/src/gcode/queue.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index 6b34a3b46b04..34754500456e 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -101,7 +101,7 @@ void GCodeQueue::RingBuffer::commit_command(const bool skip_ok commands[index_w].skip_ok = skip_ok; TERN_(HAS_MULTI_SERIAL, commands[index_w].port = serial_ind); TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w)); - advance_pos(index_w, 1); + advance_w(); } /** @@ -702,7 +702,7 @@ void GCodeQueue::advance() { #endif // HAS_MEDIA // The queue may be reset by a command handler or by code invoked by idle() within a handler - ring_buffer.advance_pos(ring_buffer.index_r, -1); + ring_buffer.advance_r(); } #if ENABLED(BUFFER_MONITORING) diff --git a/Marlin/src/gcode/queue.h b/Marlin/src/gcode/queue.h index 07e08493d1de..3779cfc4ad89 100644 --- a/Marlin/src/gcode/queue.h +++ b/Marlin/src/gcode/queue.h @@ -78,6 +78,8 @@ class GCodeQueue { inline void clear() { length = index_r = index_w = 0; } void advance_pos(uint8_t &p, const int inc) { if (++p >= BUFSIZE) p = 0; length += inc; } + inline void advance_w() { advance_pos(index_w, 1); } + inline void advance_r() { if (length) advance_pos(index_r, -1); } void commit_command(const bool skip_ok OPTARG(HAS_MULTI_SERIAL, serial_index_t serial_ind=serial_index_t())