ardupilot/libraries/AP_HAL/Semaphores.cpp
Andrew Tridgell 8f973da4b5 AP_HAL: moved the WITH_SEMAPHORE() logic into AP_HAL
this is needed to allow us to record the location of a blocking
semaphore to track down bugs where we have a semaphore deadlock
2019-05-15 15:33:48 +10:00

29 lines
606 B
C++

#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)
{
bool in_main = hal.scheduler->in_main_thread();
if (in_main) {
hal.util->persistent_data.semaphore_line = line;
}
_mtx.take_blocking();
if (in_main) {
hal.util->persistent_data.semaphore_line = 0;
}
}
WithSemaphore::~WithSemaphore()
{
_mtx.give();
}