2015-12-20 16:33:11 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
2018-08-07 03:39:42 -03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <AP_HAL/AP_HAL_Macros.h>
|
|
|
|
#include <AP_HAL/Semaphores.h>
|
|
|
|
#include "AP_HAL_SITL_Namespace.h"
|
2015-12-20 16:33:11 -04:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
class HALSITL::Semaphore : public AP_HAL::Semaphore {
|
|
|
|
public:
|
2018-08-19 22:18:27 -03:00
|
|
|
Semaphore();
|
2019-02-21 19:06:59 -04:00
|
|
|
bool give() override;
|
|
|
|
bool take(uint32_t timeout_ms) override;
|
|
|
|
bool take_nonblocking() override;
|
2020-10-11 22:24:49 -03:00
|
|
|
|
|
|
|
void check_owner(); // asserts that current thread owns semaphore
|
|
|
|
|
2018-08-19 22:18:27 -03:00
|
|
|
protected:
|
2015-12-20 16:33:11 -04:00
|
|
|
pthread_mutex_t _lock;
|
2020-10-11 22:24:49 -03:00
|
|
|
pthread_t owner;
|
|
|
|
|
2020-11-12 03:45:09 -04:00
|
|
|
// keep track the recursion level to ensure we only disown the
|
|
|
|
// semaphore once we're done with it
|
|
|
|
uint8_t take_count;
|
2015-12-20 16:33:11 -04:00
|
|
|
};
|