Semaphores.cpp 606 B

12345678910111213141516171819202122232425262728
  1. #include "AP_HAL.h"
  2. extern const AP_HAL::HAL &hal;
  3. /*
  4. implement WithSemaphore class for WITH_SEMAPHORE() support
  5. */
  6. WithSemaphore::WithSemaphore(AP_HAL::Semaphore *mtx, uint32_t line) :
  7. WithSemaphore(*mtx, line)
  8. {}
  9. WithSemaphore::WithSemaphore(AP_HAL::Semaphore &mtx, uint32_t line) :
  10. _mtx(mtx)
  11. {
  12. bool in_main = hal.scheduler->in_main_thread();
  13. if (in_main) {
  14. hal.util->persistent_data.semaphore_line = line;
  15. }
  16. _mtx.take_blocking();
  17. if (in_main) {
  18. hal.util->persistent_data.semaphore_line = 0;
  19. }
  20. }
  21. WithSemaphore::~WithSemaphore()
  22. {
  23. _mtx.give();
  24. }