uORB: add bitset for faster orb_exists check and remove uORB::Subscription lazy subscribe hack/optimization

- add PX4 bitset and atomic_bitset with testing
 - add uORB::Subscription constructor to take ORB_ID enum
 - move orb test messages into msg/
This commit is contained in:
Daniel Agar
2020-03-11 09:06:33 -04:00
committed by GitHub
parent 88c9761f1f
commit 9585055e9e
38 changed files with 919 additions and 200 deletions
+27 -47
View File
@@ -42,48 +42,49 @@
namespace uORB
{
bool
Subscription::subscribe()
bool Subscription::subscribe()
{
// valid ORB_ID required
if (_meta == nullptr) {
return false;
}
// check if already subscribed
if (_node != nullptr) {
return true;
}
DeviceMaster *device_master = uORB::Manager::get_instance()->get_device_master();
if (_orb_id != ORB_ID::INVALID) {
if (device_master != nullptr) {
uORB::DeviceNode *node = device_master->getDeviceNode(_meta, _instance);
DeviceMaster *device_master = uORB::Manager::get_instance()->get_device_master();
if (node != nullptr) {
_node = node;
_node->add_internal_subscriber();
if (device_master != nullptr) {
// If there were any previous publications, allow the subscriber to read them
const unsigned curr_gen = _node->published_message_count();
const uint8_t q_size = _node->get_queue_size();
if (q_size < curr_gen) {
_last_generation = curr_gen - q_size;
} else {
_last_generation = 0;
if (!device_master->deviceNodeExists(_orb_id, _instance)) {
return false;
}
return true;
uORB::DeviceNode *node = device_master->getDeviceNode(get_topic(), _instance);
if (node != nullptr) {
_node = node;
_node->add_internal_subscriber();
// If there were any previous publications, allow the subscriber to read them
const unsigned curr_gen = _node->published_message_count();
const uint8_t q_size = _node->get_queue_size();
if (q_size < curr_gen) {
_last_generation = curr_gen - q_size;
} else {
_last_generation = 0;
}
return true;
}
}
}
return false;
}
void
Subscription::unsubscribe()
void Subscription::unsubscribe()
{
if (_node != nullptr) {
_node->remove_internal_subscriber();
@@ -93,28 +94,7 @@ Subscription::unsubscribe()
_last_generation = 0;
}
bool
Subscription::init()
{
if (_meta != nullptr) {
// this throttles the relatively expensive calls to getDeviceNode()
if ((_last_generation == 0) || (_last_generation < 1000) || (_last_generation % 100 == 0)) {
if (subscribe()) {
return true;
}
}
if (_node == nullptr) {
// use generation to count attempts to subscribe
_last_generation++;
}
}
return false;
}
bool
Subscription::update(uint64_t *time, void *dst)
bool Subscription::update(uint64_t *time, void *dst)
{
if ((time != nullptr) && (dst != nullptr) && advertised()) {
// always copy data to dst regardless of update