diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 11:43:54 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 11:43:54 +0200 |
| commit | ee4096101da245a792cd4df68973585305d09087 (patch) | |
| tree | 982df6acd03b7a13d24a9eae665d7905376e54b3 /libs/kstd | |
| parent | 5bad38935238da045d9fd467eae9dfd958deea34 (diff) | |
| parent | a8f2e1a0edc37cd1c06447c42ff94f3370e8a6bc (diff) | |
| download | kernel-ee4096101da245a792cd4df68973585305d09087.tar.xz kernel-ee4096101da245a792cd4df68973585305d09087.zip | |
Merge branch 'fmorgner/implement-interrupt-locking' into 'develop'
kapi/interrupts: implement irq_lock
See merge request teachos/kernel!61
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 |
