The Pedigree Project 0.1
ExecutionContext.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted.
6 */
7
8#ifndef PEDIGREE_KERNEL_PROCESS_EXECUTIONCONTEXT_H
9#define PEDIGREE_KERNEL_PROCESS_EXECUTIONCONTEXT_H
10#include "pedigree/kernel/compiler.h"
11#include "pedigree/kernel/process/AtomicStateCleanup.h"
12
13#include <config.h>
14
15class Thread;
16
25enum class ExecutionContext {
26 WaitableThread,
27 AtomicThread,
28 HardDeviceIrq,
29 SchedulerIrq,
30 HostedSyntheticIrq,
31 DebuggerTrap,
32};
33
36 public:
37 ExecutionContextState(ExecutionContext context = ExecutionContext::WaitableThread)
38 : m_Context(context) {}
39
40 ExecutionContext current() const {
41 return m_Context;
42 }
43
45 ExecutionContext enter(ExecutionContext context) {
46 const ExecutionContext previous = m_Context;
47 m_Context = context;
48 return previous;
49 }
50
51 void restore(ExecutionContext context) {
52 m_Context = context;
53 }
54
55 void reset() {
56 m_Context = ExecutionContext::WaitableThread;
57 }
58
59 private:
60 ExecutionContext m_Context;
61};
62
70class EXPORTED_PUBLIC ExecutionContextGuard {
71 public:
72 explicit ExecutionContextGuard(ExecutionContext context);
74
75 private:
78
79 static void abandon(void* context);
80 void restore();
81
82 Thread* m_Thread;
83 size_t m_StateLevel;
84 ExecutionContext m_Previous;
86 bool m_Active;
87};
88
89#endif
ExecutionContext enter(ExecutionContext context)