Device:: Move to POSIX semaphore abstraction

This commit is contained in:
Lorenz Meier
2015-09-20 00:27:41 +02:00
parent d73deabf5c
commit 76508ab5b5
5 changed files with 22 additions and 38 deletions
+5 -22
View File
@@ -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