mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-30 06:25:20 -04:00
util: better match true std::atomic semantics
This commit is contained in:
parent
c6d7174dd3
commit
aed9d3f535
12 changed files with 102 additions and 53 deletions
|
@ -287,7 +287,7 @@ namespace ams::kern::arch::arm64::cpu {
|
|||
break;
|
||||
}
|
||||
|
||||
m_target_cores.FetchAnd(~(1ul << GetCurrentCoreId()));
|
||||
m_target_cores &= (~(1ul << GetCurrentCoreId()));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void SetEventLocally() {
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace ams::kern {
|
|||
void KClientPort::OnSessionFinalized() {
|
||||
KScopedSchedulerLock sl;
|
||||
|
||||
if (m_num_sessions.FetchSub(1) == m_max_sessions) {
|
||||
if (const auto prev = m_num_sessions--; prev == m_max_sessions) {
|
||||
this->NotifyAvailable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ namespace ams::kern {
|
|||
constexpr u64 ProcessIdMin = InitialProcessIdMax + 1;
|
||||
constexpr u64 ProcessIdMax = std::numeric_limits<u64>::max();
|
||||
|
||||
constinit util::Atomic<u64> g_initial_process_id{InitialProcessIdMin};
|
||||
constinit util::Atomic<u64> g_process_id{ProcessIdMin};
|
||||
constinit util::Atomic<u64> g_initial_process_id = InitialProcessIdMin;
|
||||
constinit util::Atomic<u64> g_process_id = ProcessIdMin;
|
||||
|
||||
Result TerminateChildren(KProcess *process, const KThread *thread_to_not_terminate) {
|
||||
/* Request that all children threads terminate. */
|
||||
|
@ -299,7 +299,7 @@ namespace ams::kern {
|
|||
R_TRY(m_capabilities.Initialize(caps, num_caps, std::addressof(m_page_table)));
|
||||
|
||||
/* Initialize the process id. */
|
||||
m_process_id = g_initial_process_id.FetchAdd(1);
|
||||
m_process_id = g_initial_process_id++;
|
||||
MESOSPHERE_ABORT_UNLESS(InitialProcessIdMin <= m_process_id);
|
||||
MESOSPHERE_ABORT_UNLESS(m_process_id <= InitialProcessIdMax);
|
||||
|
||||
|
@ -409,7 +409,7 @@ namespace ams::kern {
|
|||
R_TRY(m_capabilities.Initialize(user_caps, num_caps, std::addressof(m_page_table)));
|
||||
|
||||
/* Initialize the process id. */
|
||||
m_process_id = g_process_id.FetchAdd(1);
|
||||
m_process_id = g_process_id++;
|
||||
MESOSPHERE_ABORT_UNLESS(ProcessIdMin <= m_process_id);
|
||||
MESOSPHERE_ABORT_UNLESS(m_process_id <= ProcessIdMax);
|
||||
|
||||
|
@ -791,13 +791,13 @@ namespace ams::kern {
|
|||
void KProcess::IncrementRunningThreadCount() {
|
||||
MESOSPHERE_ASSERT(m_num_running_threads.Load() >= 0);
|
||||
|
||||
m_num_running_threads.FetchAdd(1);
|
||||
++m_num_running_threads;
|
||||
}
|
||||
|
||||
void KProcess::DecrementRunningThreadCount() {
|
||||
MESOSPHERE_ASSERT(m_num_running_threads.Load() > 0);
|
||||
|
||||
if (m_num_running_threads.FetchSub(1) == 1) {
|
||||
if (const auto prev = m_num_running_threads--; prev == 1) {
|
||||
this->Terminate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace ams::kern {
|
|||
|
||||
constexpr inline s32 TerminatingThreadPriority = ams::svc::SystemThreadPriorityHighest - 1;
|
||||
|
||||
constinit util::Atomic<u64> g_thread_id = 0;
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsKernelAddressKey(KProcessAddress key) {
|
||||
const uintptr_t key_uptr = GetInteger(key);
|
||||
return KernelVirtualAddressSpaceBase <= key_uptr && key_uptr <= KernelVirtualAddressSpaceLast && (key_uptr & 1) == 0;
|
||||
|
@ -219,7 +221,7 @@ namespace ams::kern {
|
|||
this->SetInExceptionHandler();
|
||||
|
||||
/* Set thread ID. */
|
||||
m_thread_id = s_next_thread_id.FetchAdd(1);
|
||||
m_thread_id = g_thread_id++;
|
||||
|
||||
/* We initialized! */
|
||||
m_initialized = true;
|
||||
|
|
|
@ -42,15 +42,15 @@ namespace ams::kern {
|
|||
return arr;
|
||||
}();
|
||||
|
||||
constinit util::Atomic<s32> g_next_ticket{0};
|
||||
constinit util::Atomic<s32> g_current_ticket{0};
|
||||
constinit util::Atomic<s32> g_next_ticket = 0;
|
||||
constinit util::Atomic<s32> g_current_ticket = 0;
|
||||
|
||||
constinit std::array<s32, cpu::NumCores> g_core_tickets = NegativeArray;
|
||||
|
||||
s32 GetCoreTicket() {
|
||||
const s32 core_id = GetCurrentCoreId();
|
||||
if (g_core_tickets[core_id] == -1) {
|
||||
g_core_tickets[core_id] = 2 * g_next_ticket.FetchAdd(1);
|
||||
g_core_tickets[core_id] = 2 * (g_next_ticket++);
|
||||
}
|
||||
return g_core_tickets[core_id];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue