mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
AP_OSD: take semaphore in OSD thread for scripting override
The scripting bindings took get_semaphore() around every OSD call, but the OSD thread updated the display without it, so a scripting draw could run concurrently with the OSD thread and the lock protected nothing. Hold the semaphore in the OSD thread around the override check and update_osd(), and set scripting_override under it, so the OSD thread and scripting draws are mutually exclusive.
This commit is contained in:
@@ -409,10 +409,11 @@ void AP_OSD::osd_thread()
|
||||
update_current_screen();
|
||||
}
|
||||
#if AP_SCRIPTING_ENABLED
|
||||
// hold the semaphore so scripting cannot draw to the OSD while the
|
||||
// OSD thread is updating it, and vice versa
|
||||
WITH_SEMAPHORE(_sem);
|
||||
if (!scripting_override) {
|
||||
#endif
|
||||
update_osd();
|
||||
#if AP_SCRIPTING_ENABLED
|
||||
} else {
|
||||
override_count++;
|
||||
if (override_count > 20) {
|
||||
@@ -421,6 +422,8 @@ void AP_OSD::osd_thread()
|
||||
override_count = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
update_osd();
|
||||
#endif // AP_SCRIPTING_ENABLED
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,6 +659,9 @@ public:
|
||||
}
|
||||
#if AP_SCRIPTING_ENABLED
|
||||
AP_OSD_Backend *scripting_get_backend() {
|
||||
// set the override under the semaphore so the OSD thread sees a
|
||||
// consistent value; the scripting binding takes it again for the call
|
||||
WITH_SEMAPHORE(_sem);
|
||||
scripting_override = true;
|
||||
override_count = 0;
|
||||
return _backends[0];
|
||||
|
||||
Reference in New Issue
Block a user