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 <keithp@keithp.com>
ao_log_end_pos = ao_log_pos_block_end(0);
if (ao_flight_number) {
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 (;;) {
/* 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 (ao_log_check(ao_log_current_pos) != AO_LOG_EMPTY)
ao_log_current_pos += AO_LOG_SIZE;
break;
}
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)
break;
if (ao_log_check(ao_log_current_pos) != AO_LOG_EMPTY) {
break;
if (ao_log_check(ao_log_current_pos) != AO_LOG_EMPTY) {
- full = ao_log_current_pos;
- empty = ao_log_current_pos;