fix(mavlink): init _mavlink_start_time before starting receiver thread

The receiver thread reads _mavlink_start_time via get_start_time() in
its first iterations, so writing it after _receiver.start() races
with the receiver. Move the assignment up so the value is published
before the receiver can observe it.
This commit is contained in:
Julian Oes
2026-07-02 08:42:49 -07:00
committed by Ramon Roche
parent 2f040a3423
commit 744eaa3390
+5 -2
View File
@@ -2578,12 +2578,15 @@ Mavlink::task_main(int argc, char *argv[])
send_autopilot_capabilities();
}
// Initialize _mavlink_start_time before starting the receiver thread —
// the receiver reads it via get_start_time(), so writing it afterwards
// would race with the receiver's first iterations.
_mavlink_start_time = hrt_absolute_time();
_receiver.start();
uint16_t event_sequence_offset = 0; // offset to account for skipped events, not sent via MAVLink
_mavlink_start_time = hrt_absolute_time();
_task_running.store(true);
while (!should_exit()) {