diff options
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/kstd/bits/concepts.hpp | 27 | ||||
| -rw-r--r-- | libs/kstd/kstd/mutex.hpp | 9 |
2 files changed, 36 insertions, 0 deletions
diff --git a/libs/kstd/kstd/bits/concepts.hpp b/libs/kstd/kstd/bits/concepts.hpp index 3e89caa9..d40b8de2 100644 --- a/libs/kstd/kstd/bits/concepts.hpp +++ b/libs/kstd/kstd/bits/concepts.hpp @@ -11,12 +11,39 @@ namespace kstd::bits concept container_compatible_range = std::ranges::input_range<RangeType> && std::convertible_to<std::ranges::range_reference_t<RangeType>, 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<typename LockableType> 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(); }; + //! 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<typename LockableType> + concept lockable = basic_lockable<LockableType> && 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<bool>; + }; + template<typename SuspectType> concept allocator_like = requires(SuspectType & suspect) { typename SuspectType::value_type; 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 <kstd/bits/concepts.hpp> #include <kstd/bits/mutex/lock_guard.hpp> // IWYU pragma: export #include <kstd/bits/mutex/mutex.hpp> // IWYU pragma: export #include <kstd/bits/mutex/tags.hpp> // IWYU pragma: export +namespace kstd +{ + + using bits::basic_lockable; + using bits::lockable; + +} // namespace kstd + #endif
\ No newline at end of file |
