Fold the useful features of alist and alist_node into ilist, and
[oota-llvm.git] / include / llvm / Support / ManagedStatic.h
index 7753105f7e61882bdbb95400e86f9663f47d94f7..28b25dbb623b0b9b90b216f50c9af81185a53858 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -34,6 +34,9 @@ protected:
   
   void RegisterManagedStatic(void *ObjPtr, void (*deleter)(void*)) const;
 public:
+  /// isConstructed - Return true if this object has not been created yet.  
+  bool isConstructed() const { return Ptr != 0; }
+  
   void destroy() const;
 };
 
@@ -70,10 +73,24 @@ public:
   }
 };
 
+template<void (*CleanupFn)(void*)>
+class ManagedCleanup : public ManagedStaticBase {
+public:
+  void Register() { RegisterManagedStatic(0, CleanupFn); }
+};
+
 
 /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
 void llvm_shutdown();
 
+  
+/// llvm_shutdown_obj - This is a simple helper class that calls
+/// llvm_shutdown() when it is destroyed.
+struct llvm_shutdown_obj {
+  llvm_shutdown_obj() {}
+  ~llvm_shutdown_obj() { llvm_shutdown(); }
+};
+  
 }
 
 #endif