mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 19:19:30 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89
Commit: 93712b24bf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256
Reviewed-by: https://github.com/sideshowbarker
4547 changed files with 104 additions and 113 deletions
57
Libraries/LibThreading/MutexProtected.h
Normal file
57
Libraries/LibThreading/MutexProtected.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <LibThreading/Mutex.h>
|
||||
|
||||
namespace Threading {
|
||||
|
||||
template<typename T>
|
||||
class MutexProtected {
|
||||
AK_MAKE_NONCOPYABLE(MutexProtected);
|
||||
AK_MAKE_NONMOVABLE(MutexProtected);
|
||||
|
||||
public:
|
||||
using ProtectedType = T;
|
||||
|
||||
ALWAYS_INLINE MutexProtected() = default;
|
||||
ALWAYS_INLINE MutexProtected(T&& value)
|
||||
: m_value(move(value))
|
||||
{
|
||||
}
|
||||
ALWAYS_INLINE explicit MutexProtected(T& value)
|
||||
: m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
decltype(auto) with_locked(Callback callback)
|
||||
{
|
||||
auto lock = this->lock();
|
||||
// This allows users to get a copy, but if we don't allow references through &m_value, it's even more complex.
|
||||
return callback(m_value);
|
||||
}
|
||||
|
||||
template<VoidFunction<T> Callback>
|
||||
void for_each_locked(Callback callback)
|
||||
{
|
||||
with_locked([&](auto& value) {
|
||||
for (auto& item : value)
|
||||
callback(item);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] ALWAYS_INLINE MutexLocker lock() { return MutexLocker(m_lock); }
|
||||
|
||||
T m_value;
|
||||
Mutex m_lock {};
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue