mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-08 17:08:28 -04:00
HAL_PX4: added Semaphore_Recursive
This commit is contained in:
parent
b347027e13
commit
1397c85f8e
@ -15,6 +15,7 @@ namespace PX4 {
|
|||||||
class PX4I2CDriver;
|
class PX4I2CDriver;
|
||||||
class PX4_I2C;
|
class PX4_I2C;
|
||||||
class Semaphore;
|
class Semaphore;
|
||||||
|
class Semaphore_Recursive;
|
||||||
class PX4CAN;
|
class PX4CAN;
|
||||||
class PX4CANManager;
|
class PX4CANManager;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,21 @@ extern const AP_HAL::HAL& hal;
|
|||||||
|
|
||||||
using namespace PX4;
|
using namespace PX4;
|
||||||
|
|
||||||
|
// construct a semaphore
|
||||||
|
Semaphore::Semaphore()
|
||||||
|
{
|
||||||
|
pthread_mutex_init(&_lock, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// construct a recursive semaphore (allows a thread to take it more than once)
|
||||||
|
Semaphore_Recursive::Semaphore_Recursive()
|
||||||
|
{
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
pthread_mutexattr_init(&attr);
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
pthread_mutex_init(&_lock, &attr);
|
||||||
|
}
|
||||||
|
|
||||||
bool Semaphore::give()
|
bool Semaphore::give()
|
||||||
{
|
{
|
||||||
return pthread_mutex_unlock(&_lock) == 0;
|
return pthread_mutex_unlock(&_lock) == 0;
|
||||||
|
@ -9,13 +9,17 @@
|
|||||||
|
|
||||||
class PX4::Semaphore : public AP_HAL::Semaphore {
|
class PX4::Semaphore : public AP_HAL::Semaphore {
|
||||||
public:
|
public:
|
||||||
Semaphore() {
|
Semaphore();
|
||||||
pthread_mutex_init(&_lock, nullptr);
|
|
||||||
}
|
|
||||||
bool give();
|
bool give();
|
||||||
bool take(uint32_t timeout_ms);
|
bool take(uint32_t timeout_ms);
|
||||||
bool take_nonblocking();
|
bool take_nonblocking();
|
||||||
private:
|
protected:
|
||||||
pthread_mutex_t _lock;
|
pthread_mutex_t _lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PX4::Semaphore_Recursive : public PX4::Semaphore {
|
||||||
|
public:
|
||||||
|
Semaphore_Recursive();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user