mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-02 05:10:35 +08:00
Device:: Move to POSIX semaphore abstraction
This commit is contained in:
@@ -55,24 +55,11 @@ Device::Device(const char *name) :
|
||||
_name(name),
|
||||
_debug_enabled(false)
|
||||
{
|
||||
#ifndef __PX4_DARWIN
|
||||
_lock = new sem_t;
|
||||
int ret = sem_init(_lock, 0, 1);
|
||||
int ret = px4_sem_init(&_lock, 0, 1);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_WARN("SEM INIT FAIL: ret %d, %s", ret, strerror(errno));
|
||||
}
|
||||
#else
|
||||
_lock_name = new char[strlen(_name) + 2];
|
||||
_lock_name[0] = '/';
|
||||
strcpy(&_lock_name[1], _name);
|
||||
/* not using O_EXCL as the device handles are unique */
|
||||
_lock = sem_open(_lock_name, O_CREAT, 0777, 1);
|
||||
|
||||
if (_lock == SEM_FAILED) {
|
||||
PX4_WARN("SEM INIT FAIL: %s", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
PX4_WARN("SEM INIT FAIL: ret %d, %s", ret, strerror(errno));
|
||||
}
|
||||
|
||||
/* setup a default device ID. When bus_type is UNKNOWN the
|
||||
other fields are invalid */
|
||||
@@ -85,11 +72,7 @@ Device::Device(const char *name) :
|
||||
|
||||
Device::~Device()
|
||||
{
|
||||
#ifdef __PX4_DARWIN
|
||||
sem_unlink(_name);
|
||||
#else
|
||||
sem_destroy(_lock);
|
||||
#endif
|
||||
px4_sem_destroy(&_lock);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user