[Mlir-commits] [mlir] [mlir] Add `MLIRContext::executeCriticalSection` and `Pass::getOpDependentDialects` methods. (PR #98953)

Mehdi Amini llvmlistbot at llvm.org
Mon Jul 15 14:49:25 PDT 2024


================
@@ -703,6 +706,24 @@ bool MLIRContext::isOperationRegistered(StringRef name) {
   return RegisteredOperationName::lookup(name, this).has_value();
 }
 
+void MLIRContext::executeCriticalSection(function_ref<void()> function) {
+  if (!function)
+    return;
+  llvm::sys::SmartScopedLock<true> lock(impl->criticalSectionMutex);
+#ifndef NDEBUG
+  // Temporarily disable `multiThreadedExecutionContext` so the context is aware
+  // only a single thread is running.
----------------
joker-eph wrote:

I don't quite understand how is this safe?

For example `executeCriticalSection` could be called from one thread, while other thread are trying to create attributes?

https://github.com/llvm/llvm-project/pull/98953


More information about the Mlir-commits mailing list