mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Inline deviceNodeExists and getDeviceNode in uORB DeviceMaster
This gives a small performance improvement Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
parent
d9498ade32
commit
3f884c5d24
@ -459,34 +459,6 @@ uORB::DeviceNode *uORB::DeviceMaster::getDeviceNode(const char *nodepath)
|
||||
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)
|
||||
{
|
||||
for (uORB::DeviceNode *node : _node_list) {
|
||||
|
||||
@ -72,9 +72,34 @@ public:
|
||||
* @return node if exists, nullptr otherwise
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if (meta == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool deviceNodeExists(ORB_ID id, const uint8_t instance);
|
||||
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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user