mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
bffcb3e92a
Enable the LOCK_DEBUG functionality for these new APIs, as it looks like we want to move the whole system to use this in the not so distant future. :^)
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/StdLibExtras.h>
|
|
#include <Kernel/Locking/Mutex.h>
|
|
|
|
namespace Kernel {
|
|
|
|
template<typename T, LockMode LockingMode>
|
|
class LockedResource {
|
|
AK_MAKE_NONCOPYABLE(LockedResource);
|
|
|
|
public:
|
|
LockedResource(T* value, Mutex& mutex, LockLocation const& location)
|
|
: m_value(value)
|
|
, m_mutex_locker(mutex, LockingMode, location)
|
|
{
|
|
}
|
|
|
|
ALWAYS_INLINE T const* operator->() const { return m_value; }
|
|
ALWAYS_INLINE T const& operator*() const { return *m_value; }
|
|
|
|
ALWAYS_INLINE T* operator->() requires(!IsConst<T>) { return m_value; }
|
|
ALWAYS_INLINE T& operator*() requires(!IsConst<T>) { return *m_value; }
|
|
|
|
ALWAYS_INLINE T const* get() const { return m_value; }
|
|
ALWAYS_INLINE T* get() requires(!IsConst<T>) { return m_value; }
|
|
|
|
private:
|
|
T* m_value;
|
|
MutexLocker m_mutex_locker;
|
|
};
|
|
|
|
class ContendedResource {
|
|
template<typename, LockMode>
|
|
friend class LockedResource;
|
|
|
|
AK_MAKE_NONCOPYABLE(ContendedResource);
|
|
AK_MAKE_NONMOVABLE(ContendedResource);
|
|
|
|
public:
|
|
ContendedResource() = default;
|
|
|
|
protected:
|
|
mutable Mutex m_mutex;
|
|
};
|
|
|
|
}
|