From ee7ad8a8996cd48eb3bb4604732096572d006712 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 29 Sep 2026 10:42:43 +0200 Subject: kstd/concepts: document basic_lockable --- libs/kstd/kstd/bits/concepts.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/bits/concepts.hpp b/libs/kstd/kstd/bits/concepts.hpp index 3e89caa9..af9f6d2c 100644 --- a/libs/kstd/kstd/bits/concepts.hpp +++ b/libs/kstd/kstd/bits/concepts.hpp @@ -11,9 +11,21 @@ namespace kstd::bits concept container_compatible_range = std::ranges::input_range && std::convertible_to, ValueType>; + //! Requirements on a basic lockable object. + //! + //! Given: + //! - @p L, a class type + //! - @p l, an instance of @p L + //! + //! @p L is said to be **lockable**, iff. the following expressions are valid: + //! - @p l.lock(); + //! - @p l.unlock(); template concept basic_lockable = requires(LockableType & lockable) { + //! Lock the lockable object, blocking until the lock has been acquired. lockable.lock(); + + //! Unlock the lockable object. lockable.unlock(); }; -- cgit v1.2.3 From 2750018596e2379a868d526262ce567a7042154d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 29 Sep 2026 10:42:57 +0200 Subject: kstd/concepts: add lockable concept --- libs/kstd/kstd/bits/concepts.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/bits/concepts.hpp b/libs/kstd/kstd/bits/concepts.hpp index af9f6d2c..d40b8de2 100644 --- a/libs/kstd/kstd/bits/concepts.hpp +++ b/libs/kstd/kstd/bits/concepts.hpp @@ -29,6 +29,21 @@ namespace kstd::bits lockable.unlock(); }; + //! Requirements on a basic lockable object. + //! + //! Given: + //! - @p L, a class type + //! - @p l, an instance of @p L + //! + //! @p L is said to be **lockable**, iff. it is a basic_lockable and the following expression is valid: + //! - @p l.try_lock(); + template + concept lockable = basic_lockable && requires(LockableType & lockable) { + //! Try to lock the lockable object, returning @p true iff. the locking was successful, @p false + //! otherwise. + { lockable.try_lock() } -> std::same_as; + }; + template concept allocator_like = requires(SuspectType & suspect) { typename SuspectType::value_type; -- cgit v1.2.3 From dd435444c5cb342ec71891fbaa17a88ecb39a234 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 29 Sep 2026 10:43:28 +0200 Subject: kstd/mutex: export lockable concepts --- libs/kstd/kstd/mutex.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/mutex.hpp b/libs/kstd/kstd/mutex.hpp index 6d482b6d..8573e5a3 100644 --- a/libs/kstd/kstd/mutex.hpp +++ b/libs/kstd/kstd/mutex.hpp @@ -1,8 +1,17 @@ #ifndef KSTD_MUTEX_HPP #define KSTD_MUTEX_HPP +#include #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export +namespace kstd +{ + + using bits::basic_lockable; + using bits::lockable; + +} // namespace kstd + #endif \ No newline at end of file -- cgit v1.2.3