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:
James Mintram 2021-10-15 20:55:22 +01:00 committed by Linus Groh
parent 8b57e56d66
commit f4fb637914
Notes: sideshowbarker 2024-07-18 02:20:05 +09:00
10 changed files with 129 additions and 66 deletions

View file

@ -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__

View file

@ -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 {

View 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 };
};
}

View 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() { }
}

View 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();
}
}

View file

@ -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 };
};
}

View file

@ -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>

View file

@ -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
)

View file

@ -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

View file

@ -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