[llvm] [Offload] Implement `olShutDown` (PR #144055)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 06:34:13 PDT 2025


================
@@ -168,15 +170,39 @@ void initPlugins() {
       !std::getenv("OFFLOAD_DISABLE_VALIDATION");
 }
 
-// TODO: We can properly reference count here and manage the resources in a more
-// clever way
 Error olInit_impl() {
-  static std::once_flag InitFlag;
-  std::call_once(InitFlag, initPlugins);
+  std::lock_guard<std::mutex> Guard{InitDeinitMtx};
+
+  if (++RefCount == 1)
+    initPlugins();
 
   return Error::success();
 }
-Error olShutDown_impl() { return Error::success(); }
+
+Error olShutDown_impl() {
+  std::lock_guard<std::mutex> Guard{InitDeinitMtx};
+
+  if (--RefCount != 0)
+    return Error::success();
+
+  llvm::Error Result = Error::success();
+
+  for (auto &P : Platforms()) {
+    // Host plugin is nullptr and has no deinit
+    if (!P.Plugin)
+      continue;
----------------
jhuber6 wrote:

We need to handle this more cleanly in the future.

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


More information about the llvm-commits mailing list