Browse Source

Inline deviceNodeExists and getDeviceNode in uORB DeviceMaster

This gives a small performance improvement

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
master
Jukka Laitinen 3 years ago committed by Beat Küng
parent
commit
3f884c5d24
  1. 28
      platforms/common/uORB/uORBDeviceMaster.cpp
  2. 31
      platforms/common/uORB/uORBDeviceMaster.hpp

28
platforms/common/uORB/uORBDeviceMaster.cpp

@ -459,34 +459,6 @@ uORB::DeviceNode *uORB::DeviceMaster::getDeviceNode(const char *nodepath)
return nullptr; return nullptr;
} }
bool uORB::DeviceMaster::deviceNodeExists(ORB_ID id, const uint8_t instance)
{
if ((id == ORB_ID::INVALID) || (instance > ORB_MULTI_MAX_INSTANCES - 1)) {
return false;
}
return _node_exists[instance][(uint8_t)id];
}
uORB::DeviceNode *uORB::DeviceMaster::getDeviceNode(const struct orb_metadata *meta, const uint8_t instance)
{
if (meta == nullptr) {
return nullptr;
}
if (!deviceNodeExists(static_cast<ORB_ID>(meta->o_id), instance)) {
return nullptr;
}
lock();
uORB::DeviceNode *node = getDeviceNodeLocked(meta, instance);
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 struct orb_metadata *meta, const uint8_t instance) uORB::DeviceNode *uORB::DeviceMaster::getDeviceNodeLocked(const struct orb_metadata *meta, const uint8_t instance)
{ {
for (uORB::DeviceNode *node : _node_list) { for (uORB::DeviceNode *node : _node_list) {

31
platforms/common/uORB/uORBDeviceMaster.hpp

@ -72,9 +72,34 @@ public:
* @return node if exists, nullptr otherwise * @return node if exists, nullptr otherwise
*/ */
uORB::DeviceNode *getDeviceNode(const char *node_name); uORB::DeviceNode *getDeviceNode(const char *node_name);
uORB::DeviceNode *getDeviceNode(const struct orb_metadata *meta, const uint8_t instance); uORB::DeviceNode *getDeviceNode(const struct orb_metadata *meta, const uint8_t instance)
{
bool deviceNodeExists(ORB_ID id, const uint8_t instance); if (meta == nullptr) {
return nullptr;
}
if (!deviceNodeExists(static_cast<ORB_ID>(meta->o_id), instance)) {
return nullptr;
}
lock();
uORB::DeviceNode *node = getDeviceNodeLocked(meta, instance);
unlock();
//We can safely return the node that can be used by any thread, because
//a DeviceNode never gets deleted.
return node;
}
bool deviceNodeExists(ORB_ID id, const uint8_t instance)
{
if ((id == ORB_ID::INVALID) || (instance > ORB_MULTI_MAX_INSTANCES - 1)) {
return false;
}
return _node_exists[instance][(uint8_t)id];
}
/** /**
* Print statistics for each existing topic. * Print statistics for each existing topic.

Loading…
Cancel
Save