From 2e66a10937ca8189498b540e3e28047d829021ad Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 7 Jun 2017 14:27:33 +0200 Subject: 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 --- CAN-binder/low-can-binding/binding/low-can-cb.cpp | 11 +++-------- CAN-binder/low-can-binding/binding/low-can-hat.hpp | 5 +++-- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'CAN-binder/low-can-binding/binding') 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 ce829b98..0671f9eb 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 can_subscription, uint32_t pid) +void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, std::map >& 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 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 can_subscription) +void on_no_clients(std::shared_ptr can_subscription, std::map >& s) { - utils::signals_manager_t& sm = utils::signals_manager_t::instance(); - std::lock_guard subscribed_signals_lock(sm.get_subscribed_signals_mutex()); - std::map >& 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 diff --git a/CAN-binder/low-can-binding/binding/low-can-hat.hpp b/CAN-binder/low-can-binding/binding/low-can-hat.hpp index 632dbc90..233d7987 100644 --- a/CAN-binder/low-can-binding/binding/low-can-hat.hpp +++ b/CAN-binder/low-can-binding/binding/low-can-hat.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include @@ -34,8 +35,8 @@ extern const struct afb_binding_interface *binder_interface; class low_can_subscription_t; -void on_no_clients(std::shared_ptr can_subscription); -void on_no_clients(std::shared_ptr can_subscription, uint32_t pid); +void on_no_clients(std::shared_ptr can_subscription, std::map >& s); +void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, std::map >& s); int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata); void subscribe(struct afb_req request); -- cgit 1.2.3-korg