stepcompress: Export steppersync_history_expire()

Don't implement history expiration from the main steppersync_flush()
code.  Instead, have callers directly invoke
steppersync_history_expire().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-08-05 14:07:59 -04:00
parent 864c78f24a
commit 7b25d1c06f
4 changed files with 15 additions and 23 deletions

View File

@ -60,8 +60,8 @@ defs_stepcompress = """
void steppersync_free(struct steppersync *ss);
void steppersync_set_time(struct steppersync *ss
, double time_offset, double mcu_freq);
int steppersync_flush(struct steppersync *ss, uint64_t move_clock
, uint64_t clear_history_clock);
void steppersync_history_expire(struct steppersync *ss, uint64_t end_clock);
int steppersync_flush(struct steppersync *ss, uint64_t move_clock);
"""
defs_itersolve = """

View File

@ -276,9 +276,9 @@ stepcompress_set_invert_sdir(struct stepcompress *sc, uint32_t invert_sdir)
}
}
// Helper to free items from the history_list
// Expire the stepcompress history older than the given clock
static void
free_history(struct stepcompress *sc, uint64_t end_clock)
stepcompress_history_expire(struct stepcompress *sc, uint64_t end_clock)
{
while (!list_empty(&sc->history_list)) {
struct history_steps *hs = list_last_entry(
@ -290,13 +290,6 @@ free_history(struct stepcompress *sc, uint64_t end_clock)
}
}
// Expire the stepcompress history older than the given clock
static void
stepcompress_history_expire(struct stepcompress *sc, uint64_t end_clock)
{
free_history(sc, end_clock);
}
// Free memory associated with a 'stepcompress' object
void __visible
stepcompress_free(struct stepcompress *sc)
@ -305,7 +298,7 @@ stepcompress_free(struct stepcompress *sc)
return;
free(sc->queue);
message_queue_free(&sc->msg_queue);
free_history(sc, UINT64_MAX);
stepcompress_history_expire(sc, UINT64_MAX);
free(sc);
}
@ -734,12 +727,11 @@ steppersync_set_time(struct steppersync *ss, double time_offset
}
// Expire the stepcompress history before the given clock time
static void
void __visible
steppersync_history_expire(struct steppersync *ss, uint64_t end_clock)
{
int i;
for (i = 0; i < ss->sc_num; i++)
{
for (i = 0; i < ss->sc_num; i++) {
struct stepcompress *sc = ss->sc_list[i];
stepcompress_history_expire(sc, end_clock);
}
@ -772,8 +764,7 @@ heap_replace(struct steppersync *ss, uint64_t req_clock)
// Find and transmit any scheduled steps prior to the given 'move_clock'
int __visible
steppersync_flush(struct steppersync *ss, uint64_t move_clock
, uint64_t clear_history_clock)
steppersync_flush(struct steppersync *ss, uint64_t move_clock)
{
// Flush each stepcompress to the specified move_clock
int i;
@ -822,6 +813,5 @@ steppersync_flush(struct steppersync *ss, uint64_t move_clock
if (!list_empty(&msgs))
serialqueue_send_batch(ss->sq, ss->cq, &msgs);
steppersync_history_expire(ss, clear_history_clock);
return 0;
}

View File

@ -42,7 +42,7 @@ struct steppersync *steppersync_alloc(
void steppersync_free(struct steppersync *ss);
void steppersync_set_time(struct steppersync *ss, double time_offset
, double mcu_freq);
int steppersync_flush(struct steppersync *ss, uint64_t move_clock
, uint64_t clear_history_clock);
void steppersync_history_expire(struct steppersync *ss, uint64_t end_clock);
int steppersync_flush(struct steppersync *ss, uint64_t move_clock);
#endif // stepcompress.h

View File

@ -17,6 +17,7 @@ class PrinterMotionQueuing:
ffi_main, ffi_lib = chelper.get_ffi()
self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves
self.steppersync_flush = ffi_lib.steppersync_flush
self.steppersync_history_expire = ffi_lib.steppersync_history_expire
def allocate_trapq(self):
ffi_main, ffi_lib = chelper.get_ffi()
trapq = ffi_main.gc(ffi_lib.trapq_alloc(), ffi_lib.trapq_free)
@ -58,12 +59,13 @@ class PrinterMotionQueuing:
clock = mcu.print_time_to_clock(print_time)
if clock < 0:
continue
clear_history_clock = \
max(0, mcu.print_time_to_clock(clear_history_time))
ret = self.steppersync_flush(ss, clock, clear_history_clock)
ret = self.steppersync_flush(ss, clock)
if ret:
raise mcu.error("Internal error in MCU '%s' stepcompress"
% (mcu.get_name(),))
clear_history_clock = \
max(0, mcu.print_time_to_clock(clear_history_time))
self.steppersync_history_expire(ss, clear_history_clock)
def wipe_trapq(self, trapq):
# Expire any remaining movement in the trapq (force to history list)
NEVER = 9999999999999999.