safer/clearer index management (#4543)
This commit is contained in:
parent
5be4586b95
commit
3112fc25de
|
@ -196,7 +196,12 @@ static void SetNextCompositeEntry(efitick_t timestamp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
composite_logger_s* entry = &buffer->buffer[buffer->nextIdx];
|
size_t idx = buffer->nextIdx;
|
||||||
|
auto nextIdx = idx + 1;
|
||||||
|
buffer->nextIdx = nextIdx;
|
||||||
|
|
||||||
|
if (idx < efi::size(buffer->buffer)) {
|
||||||
|
composite_logger_s* entry = &buffer->buffer[idx];
|
||||||
|
|
||||||
uint32_t nowUs = NT2US(timestamp);
|
uint32_t nowUs = NT2US(timestamp);
|
||||||
|
|
||||||
|
@ -208,11 +213,10 @@ static void SetNextCompositeEntry(efitick_t timestamp) {
|
||||||
entry->sync = engine->triggerCentral.triggerState.getShaftSynchronized();
|
entry->sync = engine->triggerCentral.triggerState.getShaftSynchronized();
|
||||||
entry->coil = currentCoilState;
|
entry->coil = currentCoilState;
|
||||||
entry->injector = currentInjectorState;
|
entry->injector = currentInjectorState;
|
||||||
|
}
|
||||||
buffer->nextIdx++;
|
|
||||||
|
|
||||||
// if the buffer is full...
|
// if the buffer is full...
|
||||||
bool bufferFull = buffer->nextIdx >= efi::size(buffer->buffer);
|
bool bufferFull = nextIdx >= efi::size(buffer->buffer);
|
||||||
// ... or it's been too long since the last flush
|
// ... or it's been too long since the last flush
|
||||||
bool bufferTimedOut = buffer->startTime.hasElapsedSec(5);
|
bool bufferTimedOut = buffer->startTime.hasElapsedSec(5);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue