mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-10-06 09:02:52 +08:00
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:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user