Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Remove extra loads when using `compare_exchange_weak`

NoctemCatf36bc36cd958
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h
index 8474dec33fa..a20486c9201 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -121,8 +121,8 @@ public:
}
_ALWAYS_INLINE_ T exchange_if_greater(T p_value) {
+ T tmp = value.load(std::memory_order_acquire);
while (true) {
- T tmp = value.load(std::memory_order_acquire);
if (tmp >= p_value) {
return tmp; // already greater, or equal
}
@@ -134,8 +134,8 @@ public:
}
_ALWAYS_INLINE_ T conditional_increment() {
+ T c = value.load(std::memory_order_acquire);
while (true) {
- T c = value.load(std::memory_order_acquire);
if (c == 0) {
return 0;
}