]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/seastar/include/seastar/util/critical_alloc_section.hh
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / include / seastar / util / critical_alloc_section.hh
index 0657600a72a535c24cf6ff6e36db2f4d15550e34..5cc6fee89a0fc2768e7f78a89d2a3b27dbf0c438 100644 (file)
@@ -24,6 +24,8 @@
 namespace seastar {
 namespace memory {
 
+#ifdef SEASTAR_ENABLE_ALLOC_FAILURE_INJECTION
+
 /// \cond internal
 namespace internal {
 
@@ -33,9 +35,9 @@ namespace internal {
 // completely drops the init guards - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97848).
 // In < c++20 we use `__thread` which results in no TLS init guards generated.
 #ifdef __cpp_constinit
-extern thread_local constinit int critical_alloc_section;
+extern thread_local constinit volatile int critical_alloc_section;
 #else
-extern __thread int critical_alloc_section;
+extern __thread volatile int critical_alloc_section;
 #endif
 
 } // namespace internal
@@ -54,8 +56,15 @@ extern __thread int critical_alloc_section;
 ///   See \ref set_dump_memory_diagnostics_on_alloc_failure_kind().
 class scoped_critical_alloc_section {
 public:
-    scoped_critical_alloc_section() { ++internal::critical_alloc_section; }
-    ~scoped_critical_alloc_section() { --internal::critical_alloc_section; }
+    scoped_critical_alloc_section() {
+        // we assume the critical_alloc_section is thread local
+        // and there's seastar threads are non-preemptive.
+        // Otherwise, this would require an atomic variable
+        internal::critical_alloc_section = internal::critical_alloc_section + 1;
+    }
+    ~scoped_critical_alloc_section() {
+        internal::critical_alloc_section = internal::critical_alloc_section - 1;
+    }
 };
 
 /// \brief Is the current context inside a critical alloc section?
@@ -66,5 +75,15 @@ inline bool is_critical_alloc_section() {
     return bool(internal::critical_alloc_section);
 }
 
+#else   // SEASTAR_ENABLE_ALLOC_FAILURE_INJECTION
+
+struct [[maybe_unused]] scoped_critical_alloc_section {};
+
+inline bool is_critical_alloc_section() {
+    return false;
+}
+
+#endif  // SEASTAR_ENABLE_ALLOC_FAILURE_INJECTION
+
 } // namespace seastar
 } // namespace memory