mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-03 05:20:35 +08:00
orb: rm static from DeviceMaster::_node_map & use the non-static getDeviceNode in uORB::Manager
Reasons: - DeviceMaster::_node_map does not need to be shared among instances, because there is at most 1 instance per Flavor and different Flavors have non-intersecting device paths. - Keeping it static would also require a static lock - DeviceMaster::_node_map was not locked at all when used from uORB::Manager So this fixes two synchronization issues: - Different DeviceMaster objects could access the same static data in parallel - getDeviceNode() called from uORB::Manager did not use any locking at all
This commit is contained in:
@@ -44,8 +44,6 @@
|
||||
#include <px4_sem.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
std::map<std::string, uORB::DeviceNode *> uORB::DeviceMaster::_node_map;
|
||||
|
||||
|
||||
uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(device::file_t *filp)
|
||||
{
|
||||
@@ -742,7 +740,7 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||
if (ret == -EEXIST) {
|
||||
/* if the node exists already, get the existing one and check if
|
||||
* something has been published yet. */
|
||||
uORB::DeviceNode *existing_node = GetDeviceNode(devpath);
|
||||
uORB::DeviceNode *existing_node = getDeviceNodeLocked(devpath);
|
||||
|
||||
if ((existing_node != nullptr) && !(existing_node->is_published())) {
|
||||
/* nothing has been published yet, lets claim it */
|
||||
@@ -779,7 +777,17 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||
}
|
||||
}
|
||||
|
||||
uORB::DeviceNode *uORB::DeviceMaster::GetDeviceNode(const char *nodepath)
|
||||
uORB::DeviceNode *uORB::DeviceMaster::getDeviceNode(const char *nodepath)
|
||||
{
|
||||
lock();
|
||||
uORB::DeviceNode *node = getDeviceNodeLocked(nodepath);
|
||||
unlock();
|
||||
//We can safely return the node that can be used by any thread, because
|
||||
//a DeviceNode never gets deleted.
|
||||
return node;
|
||||
}
|
||||
|
||||
uORB::DeviceNode *uORB::DeviceMaster::getDeviceNodeLocked(const char *nodepath)
|
||||
{
|
||||
uORB::DeviceNode *rc = nullptr;
|
||||
std::string np(nodepath);
|
||||
|
||||
Reference in New Issue
Block a user