8#include "pedigree/kernel/Log.h"
9#include "pedigree/kernel/process/TerminationDeferral.h"
10#include "pedigree/kernel/process/Thread.h"
11#include "pedigree/kernel/processor/Processor.h"
12#include "pedigree/kernel/processor/ProcessorInformation.h"
15#if PEDIGREE_AFFINITY_TESTS
16void reportIdentityFailure(
Thread* expected,
Thread* observed,
Thread* stable,
const void* scope,
17 const char* site,
const void* caller,
bool interrupts) {
18 ERROR_NOLOCK(
"AFFINITY-IDENTITY: expected=" <<
Hex << expected <<
" observed=" << observed);
19 ERROR_NOLOCK(
"AFFINITY-IDENTITY: stable=" <<
Hex << stable <<
" scope=" << scope);
20 ERROR_NOLOCK(
"AFFINITY-IDENTITY: site=" << site <<
" caller=" <<
Hex << caller);
21 ERROR_NOLOCK(
"AFFINITY-IDENTITY: cpu=" <<
Dec <<
Processor::index() <<
" irq=" << interrupts);
25#if PEDIGREE_AFFINITY_TESTS
28void assertCurrentThread(
Thread* thread,
const void* scope,
const char* site) {
30 if (thread && observed != thread) {
31#if PEDIGREE_AFFINITY_TESTS
35 reportIdentityFailure(thread, observed, stable, scope, site, __builtin_return_address(0),
41 FATAL(
"TerminationDeferral moved or released on a different Thread.");
46void TerminationDeferral::initialise(
bool active) {
48#if PEDIGREE_AFFINITY_TESTS
53 if (m_pThread != stable) {
54 reportIdentityFailure(m_pThread, m_pThread, stable,
this,
"construct",
55 __builtin_return_address(0), interrupts);
56 FATAL(
"TerminationDeferral captured a different Thread.");
62 m_pThread->registerFreshTerminationDeferral(m_Record);
69 : m_pThread(other.m_pThread), m_Record() {
70 assertCurrentThread(m_pThread,
this,
"move-construct");
72 m_pThread->moveTerminationDeferral(other.m_Record, m_Record);
74 other.m_pThread =
nullptr;
77TerminationDeferral::~TerminationDeferral() {
79 assertCurrentThread(m_pThread,
this,
"destroy");
80 m_pThread->unregisterTerminationDeferral(m_Record);
86 if (m_pThread && other.m_pThread) {
87 assertCurrentThread(m_pThread,
this,
"replace-destination");
88 assertCurrentThread(other.m_pThread, &other,
"replace-source");
89 if (m_pThread != other.m_pThread) {
90 FATAL(
"TerminationDeferral replaced from a different Thread.");
97 m_pThread->unregisterTerminationDeferral(other.m_Record);
98 other.m_pThread =
nullptr;
103 assertCurrentThread(m_pThread,
this,
"reset-destination");
104 m_pThread->unregisterTerminationDeferral(m_Record);
106 assertCurrentThread(other.m_pThread, &other,
"adopt-source");
107 m_pThread = other.m_pThread;
109 m_pThread->moveTerminationDeferral(other.m_Record, m_Record);
111 other.m_pThread =
nullptr;
static bool getInterrupts()
static ProcessorInformation & information()
static void setInterrupts(bool bEnable)