From: Keith Packard Date: Tue, 18 May 2021 05:38:14 +0000 (-0700) Subject: altos: Simplify discovery of log end position X-Git-Tag: 1.9.7~1^2~7^2~2 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=565778b66e59069fc6a6d6518f28354eae954dc1;p=fw%2Faltos 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 --- 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;