mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Kernel: Split ScopedCritical so header is platform independent
A new header file has been created in the Arch/ folder while the implementation has been moved into a CPP living in the X86 folder.
This commit is contained in:
parent
8b57e56d66
commit
f4fb637914
Notes:
sideshowbarker
2024-07-18 02:20:05 +09:00
Author: https://github.com/jamesmintram Commit: https://github.com/SerenityOS/serenity/commit/f4fb6379145 Pull-request: https://github.com/SerenityOS/serenity/pull/10475 Reviewed-by: https://github.com/linusg ✅
10 changed files with 129 additions and 66 deletions
|
@ -11,7 +11,7 @@
|
|||
#include <AK/Noncopyable.h>
|
||||
#ifdef KERNEL
|
||||
# include <Kernel/Arch/Processor.h>
|
||||
# include <Kernel/Arch/x86/ScopedCritical.h>
|
||||
# include <Kernel/Arch/ScopedCritical.h>
|
||||
#endif
|
||||
|
||||
#ifndef __serenity__
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "StdLibExtras.h"
|
||||
#ifdef KERNEL
|
||||
# include <Kernel/Arch/Processor.h>
|
||||
# include <Kernel/Arch/x86/ScopedCritical.h>
|
||||
# include <Kernel/Arch/ScopedCritical.h>
|
||||
#endif
|
||||
|
||||
namespace AK {
|
||||
|
|
30
Kernel/Arch/ScopedCritical.h
Normal file
30
Kernel/Arch/ScopedCritical.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Noncopyable.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class ScopedCritical {
|
||||
AK_MAKE_NONCOPYABLE(ScopedCritical);
|
||||
|
||||
public:
|
||||
ScopedCritical();
|
||||
~ScopedCritical();
|
||||
ScopedCritical(ScopedCritical&& from);
|
||||
|
||||
ScopedCritical& operator=(ScopedCritical&& from);
|
||||
|
||||
void leave();
|
||||
void enter();
|
||||
|
||||
private:
|
||||
bool m_valid { false };
|
||||
};
|
||||
|
||||
}
|
34
Kernel/Arch/aarch64/ScopedCritical.cpp
Normal file
34
Kernel/Arch/aarch64/ScopedCritical.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Arch/ScopedCritical.h>
|
||||
|
||||
#include <Kernel/Arch/Processor.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ScopedCritical::ScopedCritical()
|
||||
{
|
||||
}
|
||||
|
||||
ScopedCritical::~ScopedCritical()
|
||||
{
|
||||
}
|
||||
|
||||
ScopedCritical::ScopedCritical(ScopedCritical&& /*from*/)
|
||||
{
|
||||
}
|
||||
|
||||
ScopedCritical& ScopedCritical::operator=(ScopedCritical&& /*from*/)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ScopedCritical::leave() { }
|
||||
|
||||
void ScopedCritical::enter() { }
|
||||
|
||||
}
|
51
Kernel/Arch/x86/ScopedCritical.cpp
Normal file
51
Kernel/Arch/x86/ScopedCritical.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Arch/ScopedCritical.h>
|
||||
|
||||
#include <Kernel/Arch/Processor.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ScopedCritical::ScopedCritical()
|
||||
{
|
||||
enter();
|
||||
}
|
||||
|
||||
ScopedCritical::~ScopedCritical()
|
||||
{
|
||||
if (m_valid)
|
||||
leave();
|
||||
}
|
||||
|
||||
ScopedCritical::ScopedCritical(ScopedCritical&& from)
|
||||
: m_valid(exchange(from.m_valid, false))
|
||||
{
|
||||
}
|
||||
|
||||
ScopedCritical& ScopedCritical::operator=(ScopedCritical&& from)
|
||||
{
|
||||
if (&from != this) {
|
||||
m_valid = exchange(from.m_valid, false);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ScopedCritical::leave()
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
m_valid = false;
|
||||
Processor::leave_critical();
|
||||
}
|
||||
|
||||
void ScopedCritical::enter()
|
||||
{
|
||||
VERIFY(!m_valid);
|
||||
m_valid = true;
|
||||
Processor::enter_critical();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
#include <Kernel/Arch/Processor.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class ScopedCritical {
|
||||
AK_MAKE_NONCOPYABLE(ScopedCritical);
|
||||
|
||||
public:
|
||||
ScopedCritical()
|
||||
{
|
||||
enter();
|
||||
}
|
||||
|
||||
~ScopedCritical()
|
||||
{
|
||||
if (m_valid)
|
||||
leave();
|
||||
}
|
||||
|
||||
ScopedCritical(ScopedCritical&& from)
|
||||
: m_valid(exchange(from.m_valid, false))
|
||||
{
|
||||
}
|
||||
|
||||
ScopedCritical& operator=(ScopedCritical&& from)
|
||||
{
|
||||
if (&from != this) {
|
||||
m_valid = exchange(from.m_valid, false);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void leave()
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
m_valid = false;
|
||||
Processor::leave_critical();
|
||||
}
|
||||
|
||||
void enter()
|
||||
{
|
||||
VERIFY(!m_valid);
|
||||
m_valid = true;
|
||||
Processor::enter_critical();
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_valid { false };
|
||||
};
|
||||
|
||||
}
|
|
@ -16,13 +16,13 @@
|
|||
#include <Kernel/Thread.h>
|
||||
|
||||
#include <Kernel/Arch/Processor.h>
|
||||
#include <Kernel/Arch/ScopedCritical.h>
|
||||
#include <Kernel/Arch/x86/CPUID.h>
|
||||
#include <Kernel/Arch/x86/InterruptDisabler.h>
|
||||
#include <Kernel/Arch/x86/Interrupts.h>
|
||||
#include <Kernel/Arch/x86/MSR.h>
|
||||
#include <Kernel/Arch/x86/ProcessorInfo.h>
|
||||
#include <Kernel/Arch/x86/SafeMem.h>
|
||||
#include <Kernel/Arch/x86/ScopedCritical.h>
|
||||
#include <Kernel/Arch/x86/TrapFrame.h>
|
||||
|
||||
#include <Kernel/Memory/PageDirectory.h>
|
||||
|
|
|
@ -288,6 +288,11 @@ set(KERNEL_SOURCES
|
|||
)
|
||||
|
||||
if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
|
||||
set(KERNEL_SOURCES
|
||||
${KERNEL_SOURCES}
|
||||
Arch/x86/ScopedCritical.cpp
|
||||
)
|
||||
|
||||
set(KERNEL_SOURCES
|
||||
${KERNEL_SOURCES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/ASM_wrapper.cpp
|
||||
|
@ -361,7 +366,11 @@ if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64")
|
|||
else()
|
||||
set(SOURCES
|
||||
${SOURCES}
|
||||
${AK_SOURCES}
|
||||
|
||||
Arch/aarch64/dummy.cpp
|
||||
Arch/aarch64/ScopedCritical.cpp
|
||||
|
||||
UBSanitizer.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <AK/Types.h>
|
||||
#ifdef KERNEL
|
||||
# include <Kernel/Arch/Processor.h>
|
||||
# include <Kernel/Arch/x86/ScopedCritical.h>
|
||||
# include <Kernel/Arch/ScopedCritical.h>
|
||||
#endif
|
||||
|
||||
#define THREADSAFENONNULLREFPTR_SCRUB_BYTE 0xa1
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifdef KERNEL
|
||||
# include <Kernel/API/KResult.h>
|
||||
# include <Kernel/Arch/Processor.h>
|
||||
# include <Kernel/Arch/x86/ScopedCritical.h>
|
||||
# include <Kernel/Arch/ScopedCritical.h>
|
||||
#endif
|
||||
|
||||
#define THREADSAFEREFPTR_SCRUB_BYTE 0xa0
|
||||
|
|
Loading…
Reference in a new issue