mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
kern: correct thread termination atomicity
This commit is contained in:
parent
e5d30217d3
commit
a75c16226e
1 changed files with 2 additions and 7 deletions
|
@ -1099,13 +1099,7 @@ namespace ams::kern {
|
||||||
const bool first_request = [&] ALWAYS_INLINE_LAMBDA () -> bool {
|
const bool first_request = [&] ALWAYS_INLINE_LAMBDA () -> bool {
|
||||||
/* Perform an atomic compare-and-swap from false to true. */
|
/* Perform an atomic compare-and-swap from false to true. */
|
||||||
bool expected = false;
|
bool expected = false;
|
||||||
do {
|
return this->termination_requested.compare_exchange_strong(expected, true);
|
||||||
if (expected) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} while (!this->termination_requested.compare_exchange_weak(expected, true));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}();
|
}();
|
||||||
|
|
||||||
/* If this is the first request, start termination procedure. */
|
/* If this is the first request, start termination procedure. */
|
||||||
|
@ -1133,6 +1127,7 @@ namespace ams::kern {
|
||||||
/* If the thread is runnable, send a termination interrupt to other cores. */
|
/* If the thread is runnable, send a termination interrupt to other cores. */
|
||||||
if (this->GetState() == ThreadState_Runnable) {
|
if (this->GetState() == ThreadState_Runnable) {
|
||||||
if (const u64 core_mask = this->affinity_mask.GetAffinityMask() & ~(1ul << GetCurrentCoreId()); core_mask != 0) {
|
if (const u64 core_mask = this->affinity_mask.GetAffinityMask() & ~(1ul << GetCurrentCoreId()); core_mask != 0) {
|
||||||
|
cpu::DataSynchronizationBarrier();
|
||||||
Kernel::GetInterruptManager().SendInterProcessorInterrupt(KInterruptName_ThreadTerminate, core_mask);
|
Kernel::GetInterruptManager().SendInterProcessorInterrupt(KInterruptName_ThreadTerminate, core_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue