summaryrefslogtreecommitdiffstats
path: root/src/can_event_push.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-24 14:14:48 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-24 14:14:48 +0000
commit9a8dcb99c3efb5b00b0a014e4699655d479d9925 (patch)
tree912d8e9923b4adf71f973239500743e459bed4d3 /src/can_event_push.cpp
parent5c0c41e87ed5d1a2de7d336465c3beb3987a299f (diff)
Improve mutex lock logic.
- Use of bracket instead of unlock method - Change some mutex lock scope. - Added subscribed_signals map object mutex to manipulate it safely. Change-Id: I770c0b5701db6b1151511f7360ec31ae6dcc1de9 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can_event_push.cpp')
-rw-r--r--src/can_event_push.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/can_event_push.cpp b/src/can_event_push.cpp
index bfe8c803..fc403ee1 100644
--- a/src/can_event_push.cpp
+++ b/src/can_event_push.cpp
@@ -30,16 +30,18 @@ void can_event_push(can_bus_t& can_bus)
openxc_SimpleMessage s_message;
json_object* jo;
- while(can_bus.has_vehicle_message())
+ while(can_bus.is_pushing())
{
- std::unique_lock<std::mutex> decoded_can_message_lock(decoded_can_message_mutex);
- new_decoded_can_message.wait(decoded_can_message_lock);
+ {
+ std::unique_lock<std::mutex> decoded_can_message_lock(decoded_can_message_mutex);
+ new_decoded_can_message.wait(decoded_can_message_lock);
v_message = can_bus.next_vehicle_message();
- decoded_can_message_mutex.unlock();
+ }
s_message = get_simple_message(v_message);
- std::lock_guard<std::mutex> push_signal_lock(subscribed_signals_mutex);
+ {
+ std::lock_guard<std::mutex> subscribed_signals_lock(subscribed_signals_mutex);
std::map<std::string, struct afb_event> subscribed_signals = get_subscribed_signals();
const auto& it_event = subscribed_signals.find(s_message.name);
if(it_event != subscribed_signals.end() && afb_event_is_valid(it_event->second))
@@ -48,7 +50,6 @@ void can_event_push(can_bus_t& can_bus)
jsonify_simple(s_message, jo);
afb_event_push(it_event->second, jo);
}
- subscribed_signals_mutex.unlock();
- update_subscrided_signals.notify_one();
+ }
}
} \ No newline at end of file