mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
Kernel: Move Lockable into its own header
This commit is contained in:
parent
2c3b0baf76
commit
aea98a85d1
Notes:
sideshowbarker
2024-07-18 07:20:52 +09:00
Author: https://github.com/boricj
Commit: aea98a85d1
Pull-request: https://github.com/SerenityOS/serenity/pull/8851
Reviewed-by: https://github.com/awesomekling ✅
Reviewed-by: https://github.com/bgianfo
10 changed files with 44 additions and 23 deletions
|
@ -182,28 +182,6 @@ private:
|
|||
bool m_locked { true };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Lockable {
|
||||
public:
|
||||
Lockable() = default;
|
||||
Lockable(T&& resource)
|
||||
: m_resource(move(resource))
|
||||
{
|
||||
}
|
||||
[[nodiscard]] Mutex& lock() { return m_lock; }
|
||||
[[nodiscard]] T& resource() { return m_resource; }
|
||||
|
||||
[[nodiscard]] T lock_and_copy()
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
return m_resource;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_resource;
|
||||
Mutex m_lock;
|
||||
};
|
||||
|
||||
class ScopedLockRelease {
|
||||
AK_MAKE_NONCOPYABLE(ScopedLockRelease);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue