From 565778b66e59069fc6a6d6518f28354eae954dc1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 17 May 2021 22:38:14 -0700 Subject: [PATCH] altos: Simplify discovery of log end position Binary search using log block indices rather than byte positions. This makes the code much easier to understand as there isn't a mystic modulus. Signed-off-by: Keith Packard --- src/kernel/ao_log.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/kernel/ao_log.c b/src/kernel/ao_log.c index f0816aee..2167d145 100644 --- a/src/kernel/ao_log.c +++ b/src/kernel/ao_log.c @@ -292,28 +292,28 @@ ao_log_scan(void) ao_log_end_pos = ao_log_pos_block_end(0); if (ao_flight_number) { - uint32_t full = ao_log_current_pos; - uint32_t empty = ao_log_end_pos - AO_LOG_SIZE; + uint32_t full = (ao_log_current_pos) / AO_LOG_SIZE; + uint32_t empty = (ao_log_end_pos - AO_LOG_SIZE) / AO_LOG_SIZE; /* If there's already a flight started, then find the * end of it */ for (;;) { - ao_log_current_pos = (full + empty) >> 1; - ao_log_current_pos -= ao_log_current_pos % AO_LOG_SIZE; + uint32_t current = (full + empty) >> 1; + ao_log_current_pos = current * AO_LOG_SIZE; - if (ao_log_current_pos == full) { + if (current == full) { if (ao_log_check(ao_log_current_pos) != AO_LOG_EMPTY) ao_log_current_pos += AO_LOG_SIZE; break; } - if (ao_log_current_pos == empty) + if (current == empty) break; if (ao_log_check(ao_log_current_pos) != AO_LOG_EMPTY) { - full = ao_log_current_pos; + full = current; } else { - empty = ao_log_current_pos; + empty = current; } } ret = 1; -- 2.30.2