2019-05-11 05:13:08 -03:00
|
|
|
#include "AP_HAL.h"
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL &hal;
|
|
|
|
|
|
|
|
/*
|
|
|
|
implement WithSemaphore class for WITH_SEMAPHORE() support
|
|
|
|
*/
|
|
|
|
WithSemaphore::WithSemaphore(AP_HAL::Semaphore *mtx, uint32_t line) :
|
|
|
|
WithSemaphore(*mtx, line)
|
|
|
|
{}
|
|
|
|
|
|
|
|
WithSemaphore::WithSemaphore(AP_HAL::Semaphore &mtx, uint32_t line) :
|
|
|
|
_mtx(mtx)
|
|
|
|
{
|
2024-01-16 18:11:26 -04:00
|
|
|
#ifndef HAL_BOOTLOADER_BUILD
|
2019-05-11 05:13:08 -03:00
|
|
|
bool in_main = hal.scheduler->in_main_thread();
|
|
|
|
if (in_main) {
|
|
|
|
hal.util->persistent_data.semaphore_line = line;
|
|
|
|
}
|
2024-01-16 18:11:26 -04:00
|
|
|
#endif
|
2019-05-11 05:13:08 -03:00
|
|
|
_mtx.take_blocking();
|
2024-01-16 18:11:26 -04:00
|
|
|
#ifndef HAL_BOOTLOADER_BUILD
|
2019-05-11 05:13:08 -03:00
|
|
|
if (in_main) {
|
|
|
|
hal.util->persistent_data.semaphore_line = 0;
|
|
|
|
}
|
2024-01-16 18:11:26 -04:00
|
|
|
#endif
|
2019-05-11 05:13:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
WithSemaphore::~WithSemaphore()
|
|
|
|
{
|
|
|
|
_mtx.give();
|
|
|
|
}
|