Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Guard queue advance_r
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 28, 2024
1 parent 94e9f26 commit b53e14c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/gcode/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit b53e14c

Please sign in to comment.