diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index 6b34a3b46b..3475450045 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 07e08493d1..3779cfc4ad 100644 --- a/Marlin/src/gcode/queue.h +++ b/Marlin/src/gcode/queue.h @@ -78,6 +78,8 @@ public: 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())