aboutsummaryrefslogtreecommitdiffstats
path: root/low-can-binding/can
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-06 14:38:02 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-06 16:16:42 +0200
commite777f2d4f52e879405d3e5867174407794456da9 (patch)
tree1b6cb43566dec8ba91989b6a802d9b05336c6cf3 /low-can-binding/can
parent7bb8126d30cc4273db6937623ac62771e17cf0a0 (diff)
Fix: correctly stop the binding.
Automatically destroying C++ objects wasn't sufficient since it uses thread with locks that were waiting forever if there is no CAN bus activity. Now correctly wake-up the threads to ends them even if there without activity on the CAN bus. Change-Id: I69d74a34a8dbea4df7c8090aa47abf1c43133020 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/can')
-rw-r--r--low-can-binding/can/can-bus.cpp14
-rw-r--r--low-can-binding/can/can-bus.hpp1
2 files changed, 13 insertions, 2 deletions
diff --git a/low-can-binding/can/can-bus.cpp b/low-can-binding/can/can-bus.cpp
index d773ad35..040cb5f8 100644
--- a/low-can-binding/can/can-bus.cpp
+++ b/low-can-binding/can/can-bus.cpp
@@ -33,6 +33,16 @@
#include "../utils/signals.hpp"
#include "../utils/openxc-utils.hpp"
+/// @brief Class destructor
+///
+/// @param[in] conf_file - Stop threads and unlock them to correctly finish them
+/// even without any activity on the CAN bus.
+can_bus_t::~can_bus_t()
+{
+ stop_threads();
+ new_can_message_cv_.notify_one();
+}
+
/// @brief Class constructor
///
/// @param[in] conf_file - handle to the json configuration file.
@@ -158,8 +168,8 @@ void can_bus_t::can_decode_message()
}
can_message_lock.lock();
}
- new_decoded_can_message_.notify_one();
- can_message_lock.unlock();
+ new_decoded_can_message_.notify_one();
+ can_message_lock.unlock();
}
}
diff --git a/low-can-binding/can/can-bus.hpp b/low-can-binding/can/can-bus.hpp
index 18782669..826d7c62 100644
--- a/low-can-binding/can/can-bus.hpp
+++ b/low-can-binding/can/can-bus.hpp
@@ -70,6 +70,7 @@ private:
public:
explicit can_bus_t(utils::config_parser_t conf_file);
can_bus_t(can_bus_t&&);
+ ~can_bus_t();
void set_can_devices();
int get_can_device_index(const std::string& bus_name) const;