aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/include
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/include')
-rw-r--r--libs/kstd/include/kstd/mutex58
1 files changed, 15 insertions, 43 deletions
diff --git a/libs/kstd/include/kstd/mutex b/libs/kstd/include/kstd/mutex
index 6ae3adf..ae91970 100644
--- a/libs/kstd/include/kstd/mutex
+++ b/libs/kstd/include/kstd/mutex
@@ -5,65 +5,37 @@
namespace kstd
{
- /**
- * @brief Custom mutex implementation, that simply wraps an atomic boolean to keep track if the mutex is already in
- * use by another thread or not.
- */
+
+ //! A non-recursive mutex.
struct mutex
{
- /**
- * @brief Defaulted constructor.
- */
- mutex() = default;
-
- /**
- * @brief Defaulted destructor.
- */
- ~mutex() = default;
+ mutex();
+ ~mutex();
- /**
- * @brief Deleted copy constructor.
- */
mutex(mutex const &) = delete;
-
- /**
- * @brief Deleted move constructor.
- *
- */
mutex(mutex &&) = delete;
- /**
- * @brief Deleted copy assignment operator.
- */
auto operator=(mutex const &) -> mutex & = delete;
-
- /**
- * @brief Deleted move assignment operator.
- */
auto operator=(mutex &&) -> mutex & = delete;
- /**
- * @brief Lock the mutex (blocks for as long as it is not available).
- */
- [[gnu::section(".stl_text")]]
+ //! Lock the mutex.
+ //!
+ //! @note This function blocks for as long as the mutex is not available.
auto lock() -> void;
- /**
- * @brief Try to lock the mutex (non-blocking).
- *
- * @return True if lock has been acquired and false otherwise.
- */
- [[gnu::section(".stl_text")]]
+ //! Try to lock the mutex.
+ //!
+ //! @note This function never blocks.
+ //! @return @p true iff. the mutex was successfully locked, @p false otherwise.
auto try_lock() -> bool;
- /**
- * @brief Unlock the mutex.
- */
- [[gnu::section(".stl_text")]]
+ //! Unlock the mutex.
+ //!
+ //! @note The behavior is undefined if the mutex is not currently held by the thread unlocking it.
auto unlock() -> void;
private:
- std::atomic<bool> locked = {false}; // Atomic boolean to track if mutex is locked or not.
+ std::atomic_flag m_locked{};
};
} // namespace kstd