From 2e9f64a045b05e93e5a5584a49dbc916e20af55c Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Sat, 9 Apr 2022 21:21:21 +0200 Subject: [PATCH] Add mutex interface --- include/sta/mutex.hpp | 27 +++++++++++++++++++++++++++ src/mutex.cpp | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 include/sta/mutex.hpp create mode 100644 src/mutex.cpp diff --git a/include/sta/mutex.hpp b/include/sta/mutex.hpp new file mode 100644 index 0000000..a9869de --- /dev/null +++ b/include/sta/mutex.hpp @@ -0,0 +1,27 @@ +#ifndef STA_MUTEX_HPP +#define STA_MUTEX_HPP + + +namespace sta +{ + /** + * @brief Interface for mutex objects. + */ + class Mutex + { + public: + /** + * @brief Block until mutex has been acquired + */ + virtual void acquire() = 0; + /** + * @brief Release mutex + */ + virtual void release() = 0; + + static Mutex * ALWAYS_FREE; /**< Fake mutex that can always be acquired */ + }; +} // namespace sta + + +#endif // STA_MUTEX_HPP diff --git a/src/mutex.cpp b/src/mutex.cpp new file mode 100644 index 0000000..b861ebd --- /dev/null +++ b/src/mutex.cpp @@ -0,0 +1,20 @@ +#include + + +namespace sta +{ + /** + * @brief Dummy mutex implementation with no access control. + */ + class DummyMutex : public Mutex + { + public: + void acquire() override {} + void release() override {} + }; + + static DummyMutex dummyMutex; + + + Mutex * Mutex::ALWAYS_FREE = &dummyMutex; +} // namespace sta