7 #ifndef __core_Counted_h__ 8 #define __core_Counted_h__ 10 #define FE_COUNTED_MT FE_COUNT_MT 12 #if FE_CODEGEN<FE_DEBUG 13 #define FE_COUNTED_TRACK TRUE 15 #define FE_COUNTED_TRACK FALSE 19 #define FE_COUNTED_STORE_TRACKER FE_COUNTED_TRACK 21 #if FE_COUNTED_TRACK && !FE_COUNTED_STORE_TRACKER 22 #error Cannot have FE_COUNTED_TRACK without FE_COUNTED_STORE_TRACKER 42 #if FE_COUNTED_STORE_TRACKER 43 m_countedName=
"Counted";
52 #if FE_CODEGEN<=FE_DEBUG 55 feLog(
"Counted::~Counted invalid m_count %d\n",
66 #if FE_COUNTED_MT && (FE_COUNTED_TRACK || !defined(FE_COUNT_ASM_IMPL)) 67 RecursiveMutex::Guard guard(ms_counted_mutex);
70 #ifdef FE_COUNT_ASM_IMPL 71 feAsmIncr(&m_count, 1);
82 ms_pTracker->acquire(
this,verboseName(),m_count);
90 #if FE_COUNTED_MT && (FE_COUNTED_TRACK || !defined(FE_COUNT_ASM_IMPL)) 91 RecursiveMutex::Guard guard(ms_counted_mutex);
98 #ifdef FE_COUNT_ASM_IMPL 99 rCount=feAsmSwapIncr(&m_count, 1) + 1;
107 ms_pTracker->acquire(
this,verboseName(),rCount);
117 if(!releaseInternal())
129 #if FE_COUNTED_MT && (FE_COUNTED_TRACK || !defined(FE_COUNT_ASM_IMPL)) 130 RecursiveMutex::Guard guard(ms_counted_mutex);
135 ms_pTracker->release(
this,verboseName(),m_count-1);
138 #if FE_CODEGEN<=FE_DEBUG 141 feX(e_corrupt,
"Counted::abandon",
142 "invalid m_count %d\n",m_count);
146 #ifdef FE_COUNT_ASM_IMPL 147 feAsmIncr(&m_count, -1);
159 RecursiveMutex::Guard guard(ms_counted_mutex);
174 #if FE_COUNTED_MT && (FE_COUNTED_TRACK || !defined(FE_COUNT_ASM_IMPL)) 175 RecursiveMutex::Guard guard(ms_counted_mutex);
181 ms_pTracker->release(
this,verboseName(),m_count-1);
188 #if FE_CODEGEN<=FE_DEBUG 191 feX(e_corrupt,
"Counted::releaseInternal",
192 "invalid m_count %d\n",m_count);
196 #ifdef FE_COUNT_ASM_IMPL 197 return feAsmSwapIncr(&m_count, -1) - 1;
203 void suppressReport(
void)
208 ms_pTracker->suppress(
this);
213 #if (FE_COUNTED_MT || FE_COUNTED_TRACK) 215 static FE_DL_PUBLIC RecursiveMutex ms_counted_mutex;
221 #if FE_COUNTED_STORE_TRACKER 225 static FE_DL_PUBLIC
Tracker* ms_pTracker;
226 static FE_DL_PUBLIC U32 ms_trackerCount;
230 void setName(
const String& name) { m_countedName=name; }
232 const String verboseName(
void)
const {
return name(); }
234 const String& name(
void)
const {
return m_countedName; }
237 void setName(
const String&) {}
243 static void startTracker(
void)
244 { ms_pTracker=
new Tracker(
"Counted "); }
245 static void stopTracker(
void)
246 { ms_trackerCount=trackerCount();
249 static String reportTracker(
void)
250 { FEASSERT(ms_pTracker);
251 return ms_pTracker->report(); }
252 static U32 trackerCount(
void)
253 {
return ms_pTracker?
254 ms_pTracker->totalCount(): ms_trackerCount; }
257 static void trackReference(
void* pPtr,
void* pReference,
String what)
259 ms_pTracker->addReference(pPtr,pReference,what); }
260 static void untrackReference(
void* pPtr,
void* pReference)
262 ms_pTracker->removeReference(pPtr,pReference); }
265 static void registerRegion(
void* pPtr,U32 bytes,
String name)
267 ms_pTracker->registerRegion(pPtr,pPtr,bytes,name); }
268 static void deregisterRegion(
void* pPtr)
270 ms_pTracker->deregisterRegion(pPtr); }
272 void trackReference(
void* pReference,
String what)
274 ms_pTracker->addReference(
this,pReference,what); }
275 void untrackReference(
void* pReference)
277 ms_pTracker->removeReference(
this,pReference); }
279 void acquireRegion(
void* pPtr,
String name,
int count)
281 ms_pTracker->acquire(pPtr,name,count); }
282 void releaseRegion(
void* pPtr,
String name,
int count)
284 ms_pTracker->release(pPtr,name,count); }
287 void registerRegion(
void* pT,U32 bytes)
291 ms_pTracker->registerRegion(
this,pT,bytes,
296 static String reportTracker(
void) {
return ""; }
297 static U32 trackerCount(
void) {
return 0; }
298 void trackReference(
void* pReference,
String what) {}
299 void untrackReference(
void* pReference) {}
300 void registerRegion(
void* pT,U32 bytes) {}
virtual void acquire(void)
Increment the reference count.
Definition: Counted.h:64
virtual void acquire(int &rCount)
Increment the reference count (and get the count)
Definition: Counted.h:88
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
Watches the usage of reference counted objects.
Definition: Tracker.h:25
Automatically reference-counted string container.
Definition: String.h:128
virtual void abandon(void)
Decrement the reference count.
Definition: Counted.h:127
int count(void) const
Return the count of references.
Definition: Counted.h:156
virtual void release(void)
Decrement the reference count.
Definition: Counted.h:115
void feLogBacktrace(U32 skip)
Dump the program stack.
Definition: backtrace.cc:274
int releaseInternal(void)
Decrement the reference count.
Definition: Counted.h:172
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192