mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
Kernel: Introduce spin-locked contended and locked resource concepts
This commit is contained in:
parent
3d684316c2
commit
019ad8a507
2 changed files with 117 additions and 0 deletions
53
Kernel/Locking/SpinLockResource.h
Normal file
53
Kernel/Locking/SpinLockResource.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <Kernel/Locking/SpinLock.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
template<typename T>
|
||||
class SpinLockLockedResource {
|
||||
AK_MAKE_NONCOPYABLE(SpinLockLockedResource);
|
||||
|
||||
public:
|
||||
SpinLockLockedResource(T* value, RecursiveSpinLock& spinlock)
|
||||
: m_value(value)
|
||||
, m_scoped_spinlock(spinlock)
|
||||
{
|
||||
}
|
||||
|
||||
ALWAYS_INLINE T const* operator->() const { return m_value; }
|
||||
ALWAYS_INLINE T const& operator*() const { return *m_value; }
|
||||
|
||||
ALWAYS_INLINE T* operator->() { return m_value; }
|
||||
ALWAYS_INLINE T& operator*() { return *m_value; }
|
||||
|
||||
ALWAYS_INLINE T const* get() const { return m_value; }
|
||||
ALWAYS_INLINE T* get() { return m_value; }
|
||||
|
||||
private:
|
||||
T* m_value;
|
||||
ScopedSpinLock<RecursiveSpinLock> m_scoped_spinlock;
|
||||
};
|
||||
|
||||
class SpinLockContendedResource {
|
||||
template<typename>
|
||||
friend class SpinLockLockedResource;
|
||||
|
||||
AK_MAKE_NONCOPYABLE(SpinLockContendedResource);
|
||||
AK_MAKE_NONMOVABLE(SpinLockContendedResource);
|
||||
|
||||
public:
|
||||
SpinLockContendedResource() = default;
|
||||
|
||||
protected:
|
||||
mutable RecursiveSpinLock m_spinlock;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue