1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #pragma once
- #include "AP_HAL_Namespace.h"
- #include <AP_Common/AP_Common.h>
- #define HAL_SEMAPHORE_BLOCK_FOREVER 0
- class AP_HAL::Semaphore {
- public:
- virtual bool take(uint32_t timeout_ms) WARN_IF_UNUSED = 0 ;
- virtual bool take_nonblocking() WARN_IF_UNUSED = 0;
-
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-result"
- virtual void take_blocking() { take(HAL_SEMAPHORE_BLOCK_FOREVER); };
- #pragma GCC diagnostic pop
-
- virtual bool give() = 0;
- virtual ~Semaphore(void) {}
- };
- class WithSemaphore {
- public:
- WithSemaphore(AP_HAL::Semaphore *mtx, uint32_t line);
- WithSemaphore(AP_HAL::Semaphore &mtx, uint32_t line);
- ~WithSemaphore();
- private:
- AP_HAL::Semaphore &_mtx;
- };
- #define WITH_SEMAPHORE( sem ) JOIN( sem, __LINE__, __COUNTER__ )
- #define JOIN( sem, line, counter ) _DO_JOIN( sem, line, counter )
- #define _DO_JOIN( sem, line, counter ) WithSemaphore _getsem ## counter(sem, line)
|