From 983916e9193a65d2cbd55039cc1569c46a7081c1 Mon Sep 17 00:00:00 2001
From: lat9nq <lat9nq@gmail.com>
Date: Fri, 1 Apr 2022 19:54:35 -0400
Subject: [PATCH] k_auto_object: Fix data race

Change the memory order to acqure-release when we decrement the
reference count. Prevents a race with line 89 reported by TSan.
---
 src/core/hle/kernel/k_auto_object.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/core/hle/kernel/k_auto_object.h b/src/core/hle/kernel/k_auto_object.h
index 05779f2d55..abdb8ae7ca 100644
--- a/src/core/hle/kernel/k_auto_object.h
+++ b/src/core/hle/kernel/k_auto_object.h
@@ -163,7 +163,7 @@ public:
         do {
             ASSERT(cur_ref_count > 0);
         } while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1,
-                                                    std::memory_order_relaxed));
+                                                    std::memory_order_acq_rel));
 
         // If ref count hits zero, destroy the object.
         if (cur_ref_count - 1 == 0) {