From 026d2bdd10305dd33baca58431a296a63d274f0d Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Mon, 31 Aug 2015 19:01:37 +0200 Subject: [PATCH] Added mutex to door.cpp to prevent lock collissions Signed-off-by: Ralf Ramsauer --- doorlockd/door.cpp | 2 ++ doorlockd/door.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/doorlockd/door.cpp b/doorlockd/door.cpp index 96ac903..adf1099 100644 --- a/doorlockd/door.cpp +++ b/doorlockd/door.cpp @@ -39,6 +39,8 @@ Door::State Door::state() const void Door::lock() { + std::lock_guard l(_mutex); + _l(LogLevel::notice, "Executing Pre Lock Script"); system(PRE_LOCK_SCRIPT); diff --git a/doorlockd/door.h b/doorlockd/door.h index 614720a..134a5b0 100644 --- a/doorlockd/door.h +++ b/doorlockd/door.h @@ -3,6 +3,7 @@ #include #include +#include #include "logger.h" @@ -52,6 +53,9 @@ private: // Read by the Heartbeat thread if it should klacker the schnapper or not bool _schnapper = { false }; + // Mutex to avoid concurrent locks + std::mutex _mutex = { }; + // WiringPi GPIO Pins static constexpr int _HEARTBEATPIN = 10; static constexpr int _SCHNAPPERPIN = 7;