8#include "pedigree/kernel/Log.h"
9#include "pedigree/kernel/process/ExecutionContext.h"
10#include "pedigree/kernel/process/Thread.h"
11#include "pedigree/kernel/processor/Processor.h"
12#include "pedigree/kernel/processor/ProcessorInformation.h"
14ExecutionContextGuard::ExecutionContextGuard(ExecutionContext context)
15 : m_Thread(
Processor::information().getCurrentThread()),
17 m_Previous(ExecutionContext::AtomicThread),
27 m_StateLevel = __atomic_load_n(&m_Thread->m_nStateLevel, __ATOMIC_ACQUIRE);
28 m_Previous = m_Thread->m_StateLevels[m_StateLevel].m_ExecutionContext.current();
33 m_Thread->armAtomicStateCleanup(m_Cleanup, abandon,
this);
35 m_Thread->m_StateLevels[m_StateLevel].m_ExecutionContext.enter(context);
40ExecutionContextGuard::~ExecutionContextGuard() {
48 m_Thread->disarmAtomicStateCleanup(m_Cleanup);
52void ExecutionContextGuard::abandon(
void* context) {
59void ExecutionContextGuard::restore() {
64 if (m_StateLevel >= MAX_NESTED_EVENTS) {
65 FATAL_NOLOCK(
"Execution-context cleanup recorded an invalid state level");
static bool getInterrupts()
static void setInterrupts(bool bEnable)
ExecutionContextState m_ExecutionContext