|
| 1 | +From 945d0c390566987832d76e161d62a82828ac40d8 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Viktoria Maksimova < [email protected]> |
| 3 | +Date: Wed, 9 Sep 2020 11:41:09 +0800 |
| 4 | +Subject: [PATCH] Adding llvm::deleteManagedStaticMutex |
| 5 | + |
| 6 | +--- |
| 7 | + llvm/include/llvm/Support/ManagedStatic.h | 8 ++++++++ |
| 8 | + llvm/lib/Support/ManagedStatic.cpp | 5 +++++ |
| 9 | + 2 files changed, 13 insertions(+) |
| 10 | + |
| 11 | +diff --git a/llvm/include/llvm/Support/ManagedStatic.h b/llvm/include/llvm/Support/ManagedStatic.h |
| 12 | +index f2b41422f13..01049e72beb 100644 |
| 13 | +--- a/llvm/include/llvm/Support/ManagedStatic.h |
| 14 | ++++ b/llvm/include/llvm/Support/ManagedStatic.h |
| 15 | +@@ -113,6 +113,14 @@ public: |
| 16 | + /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. |
| 17 | + void llvm_shutdown(); |
| 18 | + |
| 19 | ++/// Purpose of this function is to free memory allocated for ManagedStaticMutex. |
| 20 | ++/// One might want to do that to avoid memory leaks in case LLVM is loaded as a |
| 21 | ++/// shared library (or dll) at runtime. |
| 22 | ++/// This function is not thread safe and should be called only if there are no |
| 23 | ++/// threads which are using the mutex now or will use the mutex in the future. |
| 24 | ++/// This means deleteManagedStaticMutex can be called only after llvm_shutdown. |
| 25 | ++void deleteManagedStaticMutex(); |
| 26 | ++ |
| 27 | + /// llvm_shutdown_obj - This is a simple helper class that calls |
| 28 | + /// llvm_shutdown() when it is destroyed. |
| 29 | + struct llvm_shutdown_obj { |
| 30 | +diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp |
| 31 | +index 053493f72fb..c843fabbe81 100644 |
| 32 | +--- a/llvm/lib/Support/ManagedStatic.cpp |
| 33 | ++++ b/llvm/lib/Support/ManagedStatic.cpp |
| 34 | +@@ -81,3 +81,8 @@ void llvm::llvm_shutdown() { |
| 35 | + while (StaticList) |
| 36 | + StaticList->destroy(); |
| 37 | + } |
| 38 | ++ |
| 39 | ++void llvm::deleteManagedStaticMutex() { |
| 40 | ++ assert(StaticList == nullptr && "llvm_shutdown() must be called first!"); |
| 41 | ++ delete ManagedStaticMutex; |
| 42 | ++} |
| 43 | +\ No newline at end of file |
| 44 | +-- |
| 45 | +2.18.1 |
| 46 | + |
0 commit comments