|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tsmartpointer.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tthreadmessage.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef TAtomicVar *TAtomicVarPtr;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const int maxClassCode = 200;
|
|
Toshihiro Shimizu |
890ddd |
TAtomicVarPtr instanceCounts[maxClassCode + 1];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline TAtomicVar &getInstanceCounter(TINT32 classCode)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(0 <= classCode && classCode <= maxClassCode);
|
|
Toshihiro Shimizu |
890ddd |
TAtomicVarPtr &instanceCountPtr = instanceCounts[classCode];
|
|
Toshihiro Shimizu |
890ddd |
if (instanceCountPtr == 0) {
|
|
Toshihiro Shimizu |
890ddd |
static TThread::Mutex mutex;
|
|
Toshihiro Shimizu |
890ddd |
TThread::MutexLocker g(&mutex);
|
|
Toshihiro Shimizu |
890ddd |
if (instanceCountPtr == 0)
|
|
Toshihiro Shimizu |
890ddd |
instanceCountPtr = new TAtomicVar();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(instanceCountPtr);
|
|
Toshihiro Shimizu |
890ddd |
return *instanceCountPtr;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INSTANCE_COUNT_ENABLED
|
|
Toshihiro Shimizu |
890ddd |
const TINT32 TSmartObject::m_unknownClassCode = 0;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TSmartObject::incrementInstanceCount()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INSTANCE_COUNT_ENABLED
|
|
Toshihiro Shimizu |
890ddd |
TAtomicVar &instanceCount = getInstanceCounter(m_classCodeRef);
|
|
Toshihiro Shimizu |
890ddd |
++instanceCount;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
assert(0);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TSmartObject::decrementInstanceCount()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INSTANCE_COUNT_ENABLED
|
|
Toshihiro Shimizu |
890ddd |
TAtomicVar &instanceCount = getInstanceCounter(m_classCodeRef);
|
|
Toshihiro Shimizu |
890ddd |
assert(instanceCount > 0);
|
|
Toshihiro Shimizu |
890ddd |
--instanceCount;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
assert(0);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 TSmartObject::getInstanceCount(ClassCode
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INSTANCE_COUNT_ENABLED
|
|
Toshihiro Shimizu |
890ddd |
code
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INSTANCE_COUNT_ENABLED
|
|
Toshihiro Shimizu |
890ddd |
TAtomicVar &instanceCount = getInstanceCounter(code);
|
|
Toshihiro Shimizu |
890ddd |
return instanceCount;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
assert(0);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|