[llvm-commits] [llvm] r127929 - in /llvm/trunk: include/llvm/Support/CrashRecoveryContext.h lib/Support/CrashRecoveryContext.cpp
Ted Kremenek
kremenek at apple.com
Fri Mar 18 17:59:37 PDT 2011
Author: kremenek
Date: Fri Mar 18 19:59:37 2011
New Revision: 127929
URL: http://llvm.org/viewvc/llvm-project?rev=127929&view=rev
Log:
Tweak CrashRecoveryContextCleanup to provide an easy method for clients to select between 'delete' and 'destructor' cleanups, and allow the destructor of CrashRecoveryContextCleanupRegister to be pseudo re-entrant.
Modified:
llvm/trunk/include/llvm/Support/CrashRecoveryContext.h
llvm/trunk/lib/Support/CrashRecoveryContext.cpp
Modified: llvm/trunk/include/llvm/Support/CrashRecoveryContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CrashRecoveryContext.h?rev=127929&r1=127928&r2=127929&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CrashRecoveryContext.h (original)
+++ llvm/trunk/include/llvm/Support/CrashRecoveryContext.h Fri Mar 18 19:59:37 2011
@@ -95,10 +95,16 @@
class CrashRecoveryContextCleanup {
public:
+ bool cleanupFired;
+ enum ProvidedCleanups { DeleteCleanup, DestructorCleanup };
+
+ CrashRecoveryContextCleanup() : cleanupFired(false) {}
virtual ~CrashRecoveryContextCleanup();
virtual void recoverResources() = 0;
- template <typename T> static CrashRecoveryContextCleanup *create(T *);
+ template <typename T> static CrashRecoveryContextCleanup *create(T *,
+ ProvidedCleanups cleanupKind =
+ CrashRecoveryContextCleanup::DeleteCleanup);
private:
friend class CrashRecoveryContext;
@@ -131,15 +137,25 @@
template <typename T>
struct CrashRecoveryContextTrait {
- static inline CrashRecoveryContextCleanup *createCleanup(T *resource) {
- return new CrashRecoveryContextDeleteCleanup<T>(resource);
+ static inline CrashRecoveryContextCleanup *
+ createCleanup(T *resource,
+ CrashRecoveryContextCleanup::ProvidedCleanups cleanup) {
+ switch (cleanup) {
+ case CrashRecoveryContextCleanup::DeleteCleanup:
+ return new CrashRecoveryContextDeleteCleanup<T>(resource);
+ case CrashRecoveryContextCleanup::DestructorCleanup:
+ return new CrashRecoveryContextDestructorCleanup<T>(resource);
+ }
+ return 0;
}
};
template<typename T>
-inline CrashRecoveryContextCleanup* CrashRecoveryContextCleanup::create(T *x) {
+inline CrashRecoveryContextCleanup*
+CrashRecoveryContextCleanup::create(T *x,
+ CrashRecoveryContextCleanup::ProvidedCleanups cleanupKind) {
return CrashRecoveryContext::GetCurrent() ?
- CrashRecoveryContextTrait<T>::createCleanup(x) :
+ CrashRecoveryContextTrait<T>::createCleanup(x, cleanupKind) :
0;
}
@@ -155,7 +171,7 @@
context->registerCleanup(cleanup);
}
~CrashRecoveryContextCleanupRegistrar() {
- if (cleanup) {
+ if (cleanup && !cleanup->cleanupFired) {
if (context)
context->unregisterCleanup(cleanup);
else
Modified: llvm/trunk/lib/Support/CrashRecoveryContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CrashRecoveryContext.cpp?rev=127929&r1=127928&r2=127929&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CrashRecoveryContext.cpp (original)
+++ llvm/trunk/lib/Support/CrashRecoveryContext.cpp Fri Mar 18 19:59:37 2011
@@ -65,6 +65,7 @@
while (i) {
CrashRecoveryContextCleanup *tmp = i;
i = tmp->next;
+ tmp->cleanupFired = true;
tmp->recoverResources();
delete tmp;
}
More information about the llvm-commits
mailing list