diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-02-23 17:52:35 +0000 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-02-23 17:52:35 +0000 |
commit | 035493b81d5bb6d909de05e9a06a0f61588a35aa (patch) | |
tree | d459e901c4b74561eb2740a74e0f1b99d6fe5ddd /src/can_event_push.cpp | |
parent | d59970dce571c1753174124326406ec1ff8e2ce8 (diff) |
First draft about lock/wait thread management.
Reordering include files
Change-Id: Ia6d9ee30eb4e1df0c380c26355679fe00b373aa8
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can_event_push.cpp')
-rw-r--r-- | src/can_event_push.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/can_event_push.cpp b/src/can_event_push.cpp index 2842c630..bfe8c803 100644 --- a/src/can_event_push.cpp +++ b/src/can_event_push.cpp @@ -18,6 +18,12 @@ #include "can_event_push.hpp" +#include "can-utils.hpp" +#include "can-signals.hpp" +#include "openxc-utils.hpp" + +#include "can_decode_message.hpp" + void can_event_push(can_bus_t& can_bus) { openxc_VehicleMessage v_message; @@ -26,15 +32,23 @@ void can_event_push(can_bus_t& can_bus) while(can_bus.has_vehicle_message()) { - v_message = can_bus.next_vehicle_message(); + 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::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)) - { - jo = json_object_new_object(); - jsonify_simple(s_message, jo); - afb_event_push(it_event->second, jo); - } + + std::lock_guard<std::mutex> push_signal_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)) + { + jo = json_object_new_object(); + 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 |