Skip to content
Snippets Groups Projects
Commit c0e3ab63 authored by Beat Küng's avatar Beat Küng Committed by Lorenz Meier
Browse files

orb: proper locking for DeviceNode::{add,remove}_internal_subscriber

parent b86cf2b0
No related branches found
No related tags found
No related merge requests found
...@@ -575,11 +575,17 @@ uORB::DeviceNode::print_statistics(bool reset) ...@@ -575,11 +575,17 @@ uORB::DeviceNode::print_statistics(bool reset)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void uORB::DeviceNode::add_internal_subscriber() void uORB::DeviceNode::add_internal_subscriber()
{ {
_subscriber_count++;
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
lock();
_subscriber_count++;
if (ch != nullptr && _subscriber_count > 0) { 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); ch->add_subscription(_meta->o_name, 1);
} else {
unlock();
} }
} }
...@@ -587,11 +593,17 @@ void uORB::DeviceNode::add_internal_subscriber() ...@@ -587,11 +593,17 @@ void uORB::DeviceNode::add_internal_subscriber()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void uORB::DeviceNode::remove_internal_subscriber() void uORB::DeviceNode::remove_internal_subscriber()
{ {
_subscriber_count--;
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
lock();
_subscriber_count--;
if (ch != nullptr && _subscriber_count == 0) { 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); ch->remove_subscription(_meta->o_name);
} else {
unlock();
} }
} }
......
...@@ -579,11 +579,17 @@ uORB::DeviceNode::print_statistics(bool reset) ...@@ -579,11 +579,17 @@ uORB::DeviceNode::print_statistics(bool reset)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void uORB::DeviceNode::add_internal_subscriber() void uORB::DeviceNode::add_internal_subscriber()
{ {
_subscriber_count++;
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
lock();
_subscriber_count++;
if (ch != nullptr && _subscriber_count > 0) { 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); ch->add_subscription(_meta->o_name, 1);
} else {
unlock();
} }
} }
...@@ -591,11 +597,17 @@ void uORB::DeviceNode::add_internal_subscriber() ...@@ -591,11 +597,17 @@ void uORB::DeviceNode::add_internal_subscriber()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void uORB::DeviceNode::remove_internal_subscriber() void uORB::DeviceNode::remove_internal_subscriber()
{ {
_subscriber_count--;
uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator(); uORBCommunicator::IChannel *ch = uORB::Manager::get_instance()->get_uorb_communicator();
lock();
_subscriber_count--;
if (ch != nullptr && _subscriber_count == 0) { 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); ch->remove_subscription(_meta->o_name);
} else {
unlock();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment