Better exclusive write implementation

This commit is contained in:
wheremyfoodat 2022-09-17 15:35:37 +03:00
parent ee74b375e3
commit 3259c5c7a6

View file

@ -46,25 +46,23 @@ public:
mem.write64(vaddr, value); mem.write64(vaddr, value);
} }
bool MemoryWriteExclusive8(u32 addr, u8 value, u8 expected) override { #define makeExclusiveWriteHandler(size) \
mem.write8(addr, value); bool MemoryWriteExclusive##size(u32 vaddr, u##size value, u##size expected) override { \
return true; u##size current = mem.read##size(vaddr); /* Get current value */ \
if (current == expected) { /* Perform the write if current == expected */ \
mem.write##size(vaddr, value); \
return true; /* Exclusive write succeeded */ \
} \
\
return false; /* Exclusive write failed */ \
} }
bool MemoryWriteExclusive16(u32 addr, u16 value, u16 expected) override { makeExclusiveWriteHandler(8)
mem.write16(addr, value); makeExclusiveWriteHandler(16)
return true; makeExclusiveWriteHandler(32)
} makeExclusiveWriteHandler(64)
bool MemoryWriteExclusive32(u32 addr, u32 value, u32 expected) override { #undef makeExclusiveWriteHandler
mem.write32(addr, value);
return true;
}
bool MemoryWriteExclusive64(u32 addr, u64 value, u64 expected) override {
mem.write64(addr, value);
return true;
}
void InterpreterFallback(u32 pc, size_t num_instructions) override { void InterpreterFallback(u32 pc, size_t num_instructions) override {
// This is never called in practice. // This is never called in practice.