[PATCH] D52425: Adding llvm::deleteManagedStaticMutex

Viktoria Maximova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 08:39:54 PDT 2018


vmaksimo created this revision.
vmaksimo added a reviewer: AlexeySotkin.
vmaksimo created this object with edit policy "Only User: vmaksimo (Viktoria Maximova)".
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D52425

Files:
  include/llvm/Support/ManagedStatic.h
  lib/Support/ManagedStatic.cpp


Index: lib/Support/ManagedStatic.cpp
===================================================================
--- lib/Support/ManagedStatic.cpp
+++ lib/Support/ManagedStatic.cpp
@@ -83,3 +83,8 @@
   while (StaticList)
     StaticList->destroy();
 }
+
+void llvm::deleteManagedStaticMutex() {
+  assert(StaticList == nullptr && "llvm_shutdown() must be called first!");
+  delete ManagedStaticMutex;
+}
\ No newline at end of file
Index: include/llvm/Support/ManagedStatic.h
===================================================================
--- include/llvm/Support/ManagedStatic.h
+++ include/llvm/Support/ManagedStatic.h
@@ -85,6 +85,14 @@
 /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
 void llvm_shutdown();
 
+/// Purpose of this function is to free memory allocated for ManagedStaticMutex.
+/// One might want to do that to avoid memory leaks in case LLVM is loaded as a
+/// shared library (or dll) at runtime.
+/// This function is not thread safe and should be called only if there are no
+/// threads which are using the mutex now or will use the mutex in the future.
+/// This means deleteManagedStaticMutex can be called only after llvm_shutdown.
+void deleteManagedStaticMutex();
+
 /// llvm_shutdown_obj - This is a simple helper class that calls
 /// llvm_shutdown() when it is destroyed.
 struct llvm_shutdown_obj {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52425.166695.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180924/041bd7de/attachment.bin>


More information about the llvm-commits mailing list