summaryrefslogtreecommitdiffstats
path: root/src/can_reader.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-23 17:52:35 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-23 17:52:35 +0000
commit035493b81d5bb6d909de05e9a06a0f61588a35aa (patch)
treed459e901c4b74561eb2740a74e0f1b99d6fe5ddd /src/can_reader.cpp
parentd59970dce571c1753174124326406ec1ff8e2ce8 (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_reader.cpp')
-rw-r--r--src/can_reader.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/can_reader.cpp b/src/can_reader.cpp
index b836570a..f984c70a 100644
--- a/src/can_reader.cpp
+++ b/src/can_reader.cpp
@@ -18,13 +18,23 @@
#include "can_reader.hpp"
+#include "low-can-binding.hpp"
+#include "can-utils.hpp"
+
void can_reader(can_bus_dev_t &can_bus_dev, can_bus_t& can_bus)
{
can_message_t can_message;
while(can_bus_dev.is_running())
{
- can_message.convert_from_canfd_frame(can_bus_dev.read());
- can_bus.push_new_can_message(can_message);
+ std::unique_lock<std::mutex> can_frame_lock(can_frame_mutex);
+ new_can_frame.wait(can_frame_lock);
+ can_message.convert_from_canfd_frame(can_bus_dev.read());
+ can_frame_mutex.unlock();
+
+ std::lock_guard<std::mutex> can_message_lock(can_message_mutex);
+ can_bus.push_new_can_message(can_message);
+ can_message_mutex.unlock();
+ new_can_message.notify_one();
}
} \ No newline at end of file