[Mlir-commits] [mlir] [mlir][python] Cache import of ir module in type casters. (PR #160000)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Mon Sep 22 02:06:50 PDT 2025
================
@@ -30,6 +32,57 @@
// clang-format on
#include "llvm/ADT/Twine.h"
+namespace mlir {
+namespace python {
+namespace {
+
+// Safely calls Python initialization code on first use, avoiding deadlocks.
+template <typename T>
+class SafeInit {
+public:
+ typedef std::unique_ptr<T> (*F)();
+
+ explicit SafeInit(F init_fn) : init_fn_(init_fn) {}
+
+ T &Get() {
+ if (T *result = output_.load()) {
----------------
ftynse wrote:
```suggestion
T &get() {
if (T *result = output.load()) {
```
https://github.com/llvm/llvm-project/pull/160000
More information about the Mlir-commits
mailing list