Spinlock/exclusive_monitor

Signed-off-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
crueter 2026-03-30 02:56:56 +00:00
parent 258cbe1653
commit a3cdea9446
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
3 changed files with 70 additions and 0 deletions

View file

@ -278,6 +278,7 @@ if ("riscv64" IN_LIST ARCHITECTURE)
backend/riscv64/emit_riscv64_vector.cpp
backend/riscv64/emit_riscv64.cpp
backend/riscv64/emit_riscv64.h
backend/riscv64/exclusive_monitor.cpp
backend/riscv64/reg_alloc.cpp
backend/riscv64/reg_alloc.h
backend/riscv64/stack_layout.h
@ -288,6 +289,8 @@ if ("riscv64" IN_LIST ARCHITECTURE)
backend/riscv64/a32_interface.cpp
backend/riscv64/a64_interface.cpp
backend/riscv64/code_block.h
common/spin_lock_riscv64.cpp
)
message(WARNING "TODO: Incomplete frontend for this host architecture")
endif()

View file

@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dynarmic/interface/exclusive_monitor.h"
#include <algorithm>
namespace Dynarmic {
ExclusiveMonitor::ExclusiveMonitor(std::size_t processor_count)
: exclusive_addresses(processor_count, INVALID_EXCLUSIVE_ADDRESS), exclusive_values(processor_count) {}
size_t ExclusiveMonitor::GetProcessorCount() const {
return exclusive_addresses.size();
}
void ExclusiveMonitor::Lock() {
lock.Lock();
}
void ExclusiveMonitor::Unlock() {
lock.Unlock();
}
bool ExclusiveMonitor::CheckAndClear(size_t processor_id, VAddr address) {
const VAddr masked_address = address & RESERVATION_GRANULE_MASK;
Lock();
if (exclusive_addresses[processor_id] != masked_address) {
Unlock();
return false;
}
for (VAddr& other_address : exclusive_addresses) {
if (other_address == masked_address) {
other_address = INVALID_EXCLUSIVE_ADDRESS;
}
}
return true;
}
void ExclusiveMonitor::Clear() {
Lock();
std::fill(exclusive_addresses.begin(), exclusive_addresses.end(), INVALID_EXCLUSIVE_ADDRESS);
Unlock();
}
void ExclusiveMonitor::ClearProcessor(size_t processor_id) {
Lock();
exclusive_addresses[processor_id] = INVALID_EXCLUSIVE_ADDRESS;
Unlock();
}
} // namespace Dynarmic

View file

@ -0,0 +1,13 @@
#include <mutex>
#include "dynarmic/common/spin_lock.h"
namespace Dynarmic {
void SpinLock::Lock() noexcept {
}
void SpinLock::Unlock() noexcept {
}
} // namespace Dynarmic