From 278e4cef84beccdd2eee4033e9675e973e17a7af Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 4 Jul 2018 20:48:02 -0400 Subject: [PATCH] uORB fix ORB_COMMUNICATOR defined sections - keep portions of internal add/remove helpers --- src/modules/uORB/uORBDevices.cpp | 25 ++++++++++++++----------- src/modules/uORB/uORBDevices.hpp | 6 +++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/modules/uORB/uORBDevices.cpp b/src/modules/uORB/uORBDevices.cpp index 871578f003..00ae985d5e 100644 --- a/src/modules/uORB/uORBDevices.cpp +++ b/src/modules/uORB/uORBDevices.cpp @@ -161,9 +161,7 @@ uORB::DeviceNode::open(device::file_t *filp) ret = CDev::open(filp); -#ifdef ORB_COMMUNICATOR add_internal_subscriber(); -#endif /* ORB_COMMUNICATOR */ if (ret != PX4_OK) { PX4_ERR("CDev::open failed"); @@ -196,9 +194,7 @@ uORB::DeviceNode::close(device::file_t *filp) hrt_cancel(&sd->update_interval->update_call); } -#ifdef ORB_COMMUNICATOR remove_internal_subscriber(); -#endif /* ORB_COMMUNICATOR */ delete sd; sd = nullptr; @@ -737,39 +733,46 @@ uORB::DeviceNode::print_statistics(bool reset) return true; } -#ifdef ORB_COMMUNICATOR void uORB::DeviceNode::add_internal_subscriber() { - uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); - lock(); _subscriber_count++; +#ifdef ORB_COMMUNICATOR + uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); + if (ch != nullptr && _subscriber_count > 0) { unlock(); //make sure we cannot deadlock if add_subscription calls back into DeviceNode ch->add_subscription(_meta->o_name, 1); - } else { + } else +#endif /* ORB_COMMUNICATOR */ + + { unlock(); } } void uORB::DeviceNode::remove_internal_subscriber() { - uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); - lock(); _subscriber_count--; +#ifdef ORB_COMMUNICATOR + uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); + if (ch != nullptr && _subscriber_count == 0) { unlock(); //make sure we cannot deadlock if remove_subscription calls back into DeviceNode ch->remove_subscription(_meta->o_name); - } else { + } else +#endif /* ORB_COMMUNICATOR */ + { unlock(); } } +#ifdef ORB_COMMUNICATOR int16_t uORB::DeviceNode::process_add_subscription(int32_t rateInHz) { // if there is already data in the node, send this out to diff --git a/src/modules/uORB/uORBDevices.hpp b/src/modules/uORB/uORBDevices.hpp index 801812ad54..3ac5b87f8a 100644 --- a/src/modules/uORB/uORBDevices.hpp +++ b/src/modules/uORB/uORBDevices.hpp @@ -139,6 +139,7 @@ public: * processed the received data message from remote. */ int16_t process_received_message(int32_t length, uint8_t *data); +#endif /* ORB_COMMUNICATOR */ /** * Add the subscriber to the node's list of subscriber. If there is @@ -156,7 +157,6 @@ public: * the Subscriber to be removed. */ void remove_internal_subscriber(); -#endif /* ORB_COMMUNICATOR */ /** * Return true if this topic has been published. @@ -182,7 +182,7 @@ public: bool print_statistics(bool reset); unsigned int get_queue_size() const { return _queue_size; } - int16_t subscriber_count() const { return _subscriber_count; } + int8_t subscriber_count() const { return _subscriber_count; } uint32_t lost_message_count() const { return _lost_messages; } unsigned int published_message_count() const { return _generation; } const struct orb_metadata *get_meta() const { return _meta; } @@ -222,7 +222,7 @@ private: uint8_t _priority; /**< priority of the topic */ bool _published{false}; /**< has ever data been published */ uint8_t _queue_size; /**< maximum number of elements in the queue */ - int16_t _subscriber_count{0}; + int8_t _subscriber_count{0}; inline static SubscriberData *filp_to_sd(device::file_t *filp);