[PATCH][llvm-c] Multithreading functions and shutdown

Moritz Maxeiner moritzmaxeiner at googlemail.com
Sat Feb 16 14:52:24 PST 2013


Add four new functions to the C API:

LLVMShutdown - exposes llvm_shutdown
LLVMStartMultithreaded - exposes llvm_start_multithreaded
LLVMStopMultithreaded - exposes llvm_stop_multithreaded
LLVMIsMultithreaded - exposes llvm_is_multithreaded
-------------- next part --------------
Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h	(revision 175375)
+++ include/llvm-c/Core.h	(working copy)
@@ -358,7 +358,12 @@
 
 void LLVMInitializeCore(LLVMPassRegistryRef R);
 
+/** Deallocate and destroy all ManagedStatic variables.
+    @see llvm::llvm_shutdown
+    @see ManagedStatic */
+void LLVMShutdown();
 
+
 /*===-- Error handling ----------------------------------------------------===*/
 
 void LLVMDisposeMessage(char *Message);
@@ -2627,6 +2632,30 @@
  */
 
 /**
+ * @defgroup LLVMCCoreThreading Threading
+ *
+ * Handle the structures needed to make LLVM safe for multithreading.
+ *
+ * @{
+ */
+
+/** Allocate and initialize structures needed to make LLVM safe for
+    multithreading. The return value indicates whether multithreaded
+    initialization succeeded. Must be executed in isolation from all
+    other LLVM api calls.
+    @see llvm::llvm_start_multithreaded */
+LLVMBool LLVMStartMultithreaded();
+
+/** Deallocate structures necessary to make LLVM safe for multithreading.
+    Must be executed in isolation from all other LLVM api calls.
+    @see llvm::llvm_stop_multithreaded */
+void LLVMStopMultithreaded();
+
+/** Check whether LLVM is executing in thread-safe mode or not.
+    @see llvm::llvm_is_multithreaded */
+LLVMBool LLVMIsMultithreaded();
+
+/**
  * @}
  */
 
@@ -2634,6 +2663,10 @@
  * @}
  */
 
+/**
+ * @}
+ */
+
 #ifdef __cplusplus
 }
 
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp	(revision 175375)
+++ lib/IR/Core.cpp	(working copy)
@@ -26,9 +26,11 @@
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/system_error.h"
+#include "llvm/Support/Threading.h"
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
@@ -48,6 +50,10 @@
   initializeCore(*unwrap(R));
 }
 
+void LLVMShutdown() {
+  llvm_shutdown();
+}
+
 /*===-- Error handling ----------------------------------------------------===*/
 
 void LLVMDisposeMessage(char *Message) {
@@ -2436,3 +2442,17 @@
 void LLVMDisposePassManager(LLVMPassManagerRef PM) {
   delete unwrap(PM);
 }
+
+/*===-- Threading ------------------------------------------------------===*/
+
+LLVMBool LLVMStartMultithreaded() {
+  return llvm_start_multithreaded();
+}
+
+void LLVMStopMultithreaded() {
+  llvm_stop_multithreaded();
+}
+
+LLVMBool LLVMIsMultithreaded() {
+  return llvm_is_multithreaded();
+}


More information about the llvm-commits mailing list