Remove redundant tracking lock checks from the hot path

This commit is contained in:
nmzik 2026-10-02 12:55:47 +04:00
parent d1c99bbfb0
commit a67a033ff8
2 changed files with 13 additions and 10 deletions

View File

@ -30,21 +30,14 @@ class TrackingSpinLock final {
public:
void lock() noexcept {
const auto thread = CurrentThread();
if (m_owner.load(std::memory_order_relaxed) == thread) {
EXIT("recursive region tracking lock\n");
}
while (m_lock.test_and_set(std::memory_order_acquire)) {
if (m_owner.load(std::memory_order_relaxed) == thread) {
EXIT("recursive region tracking lock while contended\n");
}
EXIT_NOT_IMPLEMENTED(m_owner.load(std::memory_order_relaxed) == thread);
std::atomic_signal_fence(std::memory_order_seq_cst);
}
m_owner.store(thread, std::memory_order_relaxed);
}
void unlock() noexcept {
if (m_owner.load(std::memory_order_relaxed) != CurrentThread()) {
EXIT("region tracking lock released by non-owner\n");
}
EXIT_NOT_IMPLEMENTED(m_owner.load(std::memory_order_relaxed) != CurrentThread());
m_owner.store(0, std::memory_order_relaxed);
m_lock.clear(std::memory_order_release);
}

View File

@ -871,6 +871,15 @@ void TestFullRegionGpuUnmarkBatching() {
[&]() noexcept {
(void)tracker.IsRegionCpuModified(address, page_size);
});
} else if (std::strcmp(name, "recursive-tracking-lock") == 0) {
Libs::Graphics::TrackingSpinLock lock;
lock.lock();
lock.lock();
} else if (std::strcmp(name, "non-owner-tracking-unlock") == 0) {
Libs::Graphics::TrackingSpinLock lock;
lock.lock();
std::thread worker([&] { lock.unlock(); });
worker.join();
}
std::_Exit(0x7f);
}
@ -928,7 +937,8 @@ void CheckDeathCase(const char *name) {
}
void TestFatalPaths() {
for (const char *name : {"gpu-dirty-explicit-cpu", "reentrant-upload"}) {
for (const char *name : {"gpu-dirty-explicit-cpu", "reentrant-upload",
"recursive-tracking-lock", "non-owner-tracking-unlock"}) {
CheckDeathCase(name);
}
}