diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-06-07 14:27:33 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-06-07 14:27:33 +0200 |
commit | 2e66a10937ca8189498b540e3e28047d829021ad (patch) | |
tree | 4cc4029b742334e487b7369683fc0f8e05e4107d /CAN-binder/low-can-binding/binding/low-can-cb.cpp | |
parent | 4eb1cc0d69804337ac9e35dea6cc2e22c0fc76c6 (diff) |
Improve reliability on multi-threading.
- Limits call to signals_manager and subscribed signals map
- Unlock and lock mutex in the right order to avoid possible dead locks.
Change-Id: Ifb152af833ad8bdde5dc4fc3a27b1a7c27046523
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/binding/low-can-cb.cpp')
-rw-r--r-- | CAN-binder/low-can-binding/binding/low-can-cb.cpp | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.cpp b/CAN-binder/low-can-binding/binding/low-can-cb.cpp index ce829b9..0671f9e 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp @@ -47,7 +47,7 @@ extern "C" /// ///*******************************************************************************/ -void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, uint32_t pid) +void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, uint32_t pid, std::map<int, std::shared_ptr<low_can_subscription_t> >& s) { if( ! can_subscription->get_diagnostic_message().empty() && can_subscription->get_diagnostic_message(pid) != nullptr) { @@ -57,14 +57,11 @@ void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, uin application_t::instance().get_diagnostic_manager().cleanup_request(adr, true); } - on_no_clients(can_subscription); + on_no_clients(can_subscription, s); } -void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription) +void on_no_clients(std::shared_ptr<low_can_subscription_t> can_subscription, std::map<int, std::shared_ptr<low_can_subscription_t> >& s) { - utils::signals_manager_t& sm = utils::signals_manager_t::instance(); - std::lock_guard<std::mutex> subscribed_signals_lock(sm.get_subscribed_signals_mutex()); - std::map<int, std::shared_ptr<low_can_subscription_t> >& s = sm.get_subscribed_signals(); auto it = s.find(can_subscription->get_index()); s.erase(it); } @@ -208,8 +205,6 @@ static int subscribe_unsubscribe_diagnostic_messages(struct afb_req request, boo } else { - diag_m.cleanup_request( - diag_m.find_recurring_request(*diag_req), true); if(sig->get_supported()) {DEBUG(binder_interface, "%s: %s cancelled due to unsubscribe", __FUNCTION__, sig->get_name().c_str());} else |