forked from Archive/PX4-Autopilot
Device:: Move to POSIX semaphore abstraction
This commit is contained in:
parent
d73deabf5c
commit
76508ab5b5
|
@ -306,7 +306,7 @@ CDev::poll(file_t *filp, struct pollfd *fds, bool setup)
|
|||
|
||||
/* yes? post the notification */
|
||||
if (fds->revents != 0)
|
||||
sem_post(fds->sem);
|
||||
px4_sem_post(fds->sem);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -343,7 +343,7 @@ CDev::poll_notify_one(struct pollfd *fds, pollevent_t events)
|
|||
/* if the state is now interesting, wake the waiter if it's still asleep */
|
||||
/* XXX semcount check here is a vile hack; counting semphores should not be abused as cvars */
|
||||
if ((fds->revents != 0) && (fds->sem->semcount <= 0))
|
||||
sem_post(fds->sem);
|
||||
px4_sem_post(fds->sem);
|
||||
}
|
||||
|
||||
pollevent_t
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -366,7 +366,7 @@ VDev::poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup)
|
|||
|
||||
/* yes? post the notification */
|
||||
if (fds->revents != 0)
|
||||
sem_post(fds->sem);
|
||||
px4_sem_post(fds->sem);
|
||||
} else {
|
||||
PX4_WARN("Store Poll Waiter error.");
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ VDev::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events)
|
|||
{
|
||||
PX4_DEBUG("VDev::poll_notify_one");
|
||||
int value;
|
||||
sem_getvalue(fds->sem, &value);
|
||||
px4_sem_getvalue(fds->sem, &value);
|
||||
|
||||
/* update the reported event set */
|
||||
fds->revents |= fds->events & events;
|
||||
|
@ -412,8 +412,9 @@ VDev::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events)
|
|||
|
||||
/* if the state is now interesting, wake the waiter if it's still asleep */
|
||||
/* XXX semcount check here is a vile hack; counting semphores should not be abused as cvars */
|
||||
if ((fds->revents != 0) && (value <= 0))
|
||||
sem_post(fds->sem);
|
||||
if ((fds->revents != 0) && (value <= 0)) {
|
||||
px4_sem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
|
||||
pollevent_t
|
||||
|
|
|
@ -181,7 +181,7 @@ protected:
|
|||
*/
|
||||
void lock() {
|
||||
DEVICE_DEBUG("lock");
|
||||
do {} while (sem_wait(_lock) != 0);
|
||||
do {} while (px4_sem_wait(&_lock) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,11 +189,11 @@ protected:
|
|||
*/
|
||||
void unlock() {
|
||||
DEVICE_DEBUG("unlock");
|
||||
sem_post(_lock);
|
||||
px4_sem_post(&_lock);
|
||||
}
|
||||
|
||||
private:
|
||||
sem_t * _lock;
|
||||
px4_sem_t _lock;
|
||||
|
||||
/** disable copy construction for this and all subclasses */
|
||||
Device(const Device &);
|
||||
|
|
|
@ -56,8 +56,8 @@ extern "C" {
|
|||
|
||||
static void timer_cb(void *data)
|
||||
{
|
||||
sem_t *p_sem = (sem_t *)data;
|
||||
sem_post(p_sem);
|
||||
px4_sem_t *p_sem = (px4_sem_t *)data;
|
||||
px4_sem_post(p_sem);
|
||||
PX4_DEBUG("timer_handler: Timer expired");
|
||||
}
|
||||
|
||||
|
@ -193,13 +193,13 @@ int px4_ioctl(int fd, int cmd, unsigned long arg)
|
|||
|
||||
int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
sem_t sem;
|
||||
px4_sem_t sem;
|
||||
int count = 0;
|
||||
int ret;
|
||||
unsigned int i;
|
||||
|
||||
PX4_DEBUG("Called px4_poll timeout = %d", timeout);
|
||||
sem_init(&sem, 0, 0);
|
||||
px4_sem_init(&sem, 0, 0);
|
||||
|
||||
// For each fd
|
||||
for (i=0; i<nfds; ++i)
|
||||
|
@ -228,7 +228,7 @@ int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
|
|||
work_s _hpwork;
|
||||
|
||||
hrt_work_queue(&_hpwork, (worker_t)&timer_cb, (void *)&sem, 1000*timeout);
|
||||
sem_wait(&sem);
|
||||
px4_sem_wait(&sem);
|
||||
|
||||
// Make sure timer thread is killed before sem goes
|
||||
// out of scope
|
||||
|
@ -236,7 +236,7 @@ int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
|
|||
}
|
||||
else
|
||||
{
|
||||
sem_wait(&sem);
|
||||
px4_sem_wait(&sem);
|
||||
}
|
||||
|
||||
// For each fd
|
||||
|
@ -258,7 +258,7 @@ int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
|
|||
}
|
||||
}
|
||||
|
||||
sem_destroy(&sem);
|
||||
px4_sem_destroy(&sem);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue