orb: move SmartLock into global space and use it also for NuttX

This commit is contained in:
Beat Küng
2016-04-26 09:55:02 +02:00
committed by Lorenz Meier
parent 4269db73a0
commit 1ce5d795be
5 changed files with 78 additions and 33 deletions
+3 -10
View File
@@ -40,6 +40,7 @@
#include "uORBUtils.hpp"
#include "uORBManager.hpp"
#include "uORBCommunicator.hpp"
#include <px4_sem.hpp>
#include <stdlib.h>
uORB::ORBMap uORB::DeviceMaster::_node_map;
@@ -603,9 +604,6 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
return ret;
}
/* ensure that only one advertiser runs through this critical section */
lock();
ret = ERROR;
/* try for topic groups */
@@ -619,11 +617,12 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
group_tries = *adv->instance;
if (group_tries >= max_group_tries) {
unlock();
return -ENOMEM;
}
}
SmartLock smart_lock(_lock);
do {
/* if path is modifyable change try index */
if (adv->instance != nullptr) {
@@ -636,7 +635,6 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
objname = strdup(meta->o_name);
if (objname == nullptr) {
unlock();
return -ENOMEM;
}
@@ -644,7 +642,6 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
devpath = strdup(nodepath);
if (devpath == nullptr) {
unlock();
free((void *)objname);
return -ENOMEM;
}
@@ -654,7 +651,6 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
/* if we didn't get a device, that's bad */
if (node == nullptr) {
unlock();
free((void *)objname);
free((void *)devpath);
return -ENOMEM;
@@ -698,9 +694,6 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
ret = -ENOMEM;
}
/* the file handle for the driver has been created, unlock */
unlock();
return ret;
}