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

Ross Brunton via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 06:28:47 PDT 2025


================
@@ -168,15 +172,41 @@ 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);
+  // While the refcount increment ensures that only thread performs
+  // initialization, we need to ensure that other threads are blocked until it
+  // is completed - hence this mutex.
+  static std::mutex Init{};
+  std::lock_guard<std::mutex> Guard{Init};
----------------
RossBrunton wrote:

Ah right, because we could call init while it is being torn down. I've just copied the logic from libomptarget.

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


More information about the llvm-commits mailing list