LLVM API Documentation
00001 //===-- ManagedStatic.cpp - Static Global wrapper -------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the ManagedStatic class and llvm_shutdown(). 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Support/ManagedStatic.h" 00015 #include <cassert> 00016 using namespace llvm; 00017 00018 static const ManagedStaticBase *StaticList = 0; 00019 00020 void ManagedStaticBase::RegisterManagedStatic(void *ObjPtr, 00021 void (*Deleter)(void*)) const { 00022 assert(Ptr == 0 && DeleterFn == 0 && Next == 0 && 00023 "Partially init static?"); 00024 Ptr = ObjPtr; 00025 DeleterFn = Deleter; 00026 00027 // Add to list of managed statics. 00028 Next = StaticList; 00029 StaticList = this; 00030 } 00031 00032 void ManagedStaticBase::destroy() const { 00033 assert(DeleterFn && "ManagedStatic not initialized correctly!"); 00034 assert(StaticList == this && 00035 "Not destroyed in reverse order of construction?"); 00036 // Unlink from list. 00037 StaticList = Next; 00038 Next = 0; 00039 00040 // Destroy memory. 00041 DeleterFn(Ptr); 00042 00043 // Cleanup. 00044 Ptr = 0; 00045 DeleterFn = 0; 00046 } 00047 00048 /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. 00049 void llvm::llvm_shutdown() { 00050 while (StaticList) 00051 StaticList->destroy(); 00052 } 00053