Skip to content

armgit / godot

Public Imported from GitHub
0

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

Add `set_if_clear()` and `clear_if_set()` to `SafeFlag`, to conditionally trigger the flag.

Lukas Tenbrink1f18494d0241
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h
index df243409003..8474dec33fa 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -164,10 +164,18 @@ public:
flag.store(true, std::memory_order_release);
}
+ _ALWAYS_INLINE_ bool set_if_clear() {
+ return !flag.exchange(true, std::memory_order_acq_rel);
+ }
+
_ALWAYS_INLINE_ void clear() {
flag.store(false, std::memory_order_release);
}
+ _ALWAYS_INLINE_ bool clear_if_set() {
+ return flag.exchange(false, std::memory_order_acq_rel);
+ }
+
_ALWAYS_INLINE_ void set_to(bool p_value) {
flag.store(p_value, std::memory_order_release);
}