From 7d9b5ce725258b875ce0ac346cfe4cc02f1069e2 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Sun, 2 Jan 2011 10:47:08 +0100 Subject: [PATCH] added convenience macros --- pvDataApp/misc/showConstructDestruct.h | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pvDataApp/misc/showConstructDestruct.h b/pvDataApp/misc/showConstructDestruct.h index f8fe20c..e41daa1 100644 --- a/pvDataApp/misc/showConstructDestruct.h +++ b/pvDataApp/misc/showConstructDestruct.h @@ -49,5 +49,50 @@ private: extern ShowConstructDestruct* getShowConstructDestruct(); + + +/* convenience macros - no getTotalReferenceCount() support */ + +#define PVDATA_REFCOUNT_MONITOR_DEFINE(NAME) \ + static volatile int64 NAME ## _totalConstruct = 0; \ + static volatile int64 NAME ## _totalDestruct = 0; \ + static Mutex * NAME ## _globalMutex = 0; \ + \ + static int64 NAME ## _processTotalConstruct() \ + { \ + Lock xx(NAME ## _globalMutex); \ + return NAME ## _totalConstruct; \ + } \ + \ + static int64 NAME ## _processTotalDestruct() \ + { \ + Lock xx(NAME ## _globalMutex); \ + return NAME ## _totalDestruct; \ + } \ + \ + static ConstructDestructCallback * NAME ## _pConstructDestructCallback; \ + \ + static void NAME ## _init() \ + { \ + static Mutex mutex = Mutex(); \ + Lock xx(&mutex); \ + if(NAME ## _globalMutex==0) { \ + NAME ## _globalMutex = new Mutex(); \ + NAME ## _pConstructDestructCallback = new ConstructDestructCallback( \ + String(#NAME), \ + NAME ## _processTotalConstruct,NAME ## _processTotalDestruct,0); \ + } \ + } + +#define PVDATA_REFCOUNT_MONITOR_DESTRUCT(NAME) \ + Lock xx(NAME ## _globalMutex); \ + NAME ## _totalDestruct++; + +#define PVDATA_REFCOUNT_MONITOR_CONSTRUCT(NAME) \ + NAME ## _init(); \ + Lock xx(NAME ## _globalMutex); \ + NAME ## _totalConstruct++; + + }} #endif /* SHOWCONSTRUCTDESTRUCT_H */