Fix: correctly stop the binding. 79/15079/3
authorRomain Forlot <romain.forlot@iot.bzh>
Fri, 6 Jul 2018 12:38:02 +0000 (14:38 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Fri, 6 Jul 2018 14:16:42 +0000 (16:16 +0200)
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>
low-can-binding/can/can-bus.cpp
low-can-binding/can/can-bus.hpp

index d773ad3..040cb5f 100644 (file)
 #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();
        }
 }
 
index 1878266..826d7c6 100644 (file)
@@ -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;