From bd3843871073970f8437f84418085af2fa6b6e55 Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 5 Oct 2005 18:25:48 +0000 Subject: [PATCH] PR: trace debug at exit --- src/Basics/BasicsGenericDestructor.cxx | 53 ++++++++++++------- src/Basics/BasicsGenericDestructor.hxx | 42 ++++++++++++--- src/SALOMELocalTrace/FileTraceCollector.cxx | 16 +++--- src/SALOMELocalTrace/LocalTraceBufferPool.cxx | 4 +- .../SALOMETraceCollector.cxx | 6 +-- 5 files changed, 81 insertions(+), 40 deletions(-) diff --git a/src/Basics/BasicsGenericDestructor.cxx b/src/Basics/BasicsGenericDestructor.cxx index f7707902f..91585a2ae 100644 --- a/src/Basics/BasicsGenericDestructor.cxx +++ b/src/Basics/BasicsGenericDestructor.cxx @@ -42,6 +42,14 @@ pthread_mutex_t PROTECTED_DELETE::_listMutex; std::list *GENERIC_DESTRUCTOR::Destructors = 0; static bool atExitSingletonDone = false ; +// ============================================================================ +/*! + * deleteInstance deletes only once the object. Only object present on the + * static list of PROTECTED_DELETE* are deleted, then removed of the list. + * The operation is protected by a mutex. + */ +// ============================================================================ + void PROTECTED_DELETE::deleteInstance(PROTECTED_DELETE *anObject) { if (std::find(_objList.begin(), _objList.end(),anObject) == _objList.end()) @@ -53,25 +61,37 @@ void PROTECTED_DELETE::deleteInstance(PROTECTED_DELETE *anObject) if (std::find(_objList.begin(), _objList.end(), anObject) != _objList.end()) { - cerr << "PROTECTED_DELETE::deleteInstance1 " << anObject << endl; + DEVTRACE("PROTECTED_DELETE::deleteInstance1 " << anObject); delete anObject; - cerr << "PROTECTED_DELETE::deleteInstance2 " << &_objList << endl; + DEVTRACE("PROTECTED_DELETE::deleteInstance2 " << &_objList); _objList.remove(anObject); - cerr << "PROTECTED_DELETE::deleteInstance3" << endl; } ret = pthread_mutex_unlock(&_listMutex); // release lock } } +// ============================================================================ +/*! + * To allow a further destruction of a PRTECTED_DELETE object, it must be added + * to the static list of PROTECTED_DELETE* + */ +// ============================================================================ + void PROTECTED_DELETE::addObj(PROTECTED_DELETE *anObject) { - cerr << "PROTECTED_DELETE::addObj " << anObject << endl; + DEVTRACE("PROTECTED_DELETE::addObj " << anObject); _objList.push_back(anObject); } +// ============================================================================ +/*! + * Herited classes have there own destructors + */ +// ============================================================================ + PROTECTED_DELETE::~PROTECTED_DELETE() { - cerr << "PROTECTED_DELETE::~PROTECTED_DELETE()" << endl; + DEVTRACE("PROTECTED_DELETE::~PROTECTED_DELETE()"); } // ============================================================================ @@ -92,7 +112,7 @@ public: { if (Make_ATEXIT && !atExitSingletonDone) { - cerr << "atExitSingleton(" << Make_ATEXIT << ")" << endl; + DEVTRACE("atExitSingleton(" << Make_ATEXIT << ")"); assert(GENERIC_DESTRUCTOR::Destructors == 0); GENERIC_DESTRUCTOR::Destructors = new std::list; int cr = atexit(HouseKeeping); @@ -103,7 +123,7 @@ public: ~atExitSingleton() { - cerr << "atExitSingleton::~atExitSingleton()" << endl << flush; + DEVTRACE("atExitSingleton::~atExitSingleton()"); } }; @@ -121,7 +141,7 @@ static atExitSingleton HouseKeeper = atExitSingleton(false); void HouseKeeping( void ) { - cerr << "HouseKeeping()" << endl; + DEVTRACE("HouseKeeping()"); assert(GENERIC_DESTRUCTOR::Destructors); if(GENERIC_DESTRUCTOR::Destructors->size()) { @@ -132,22 +152,22 @@ void HouseKeeping( void ) { it-- ; GENERIC_DESTRUCTOR* ptr = *it ; - cerr << "HouseKeeping() " << typeid(ptr).name() << endl; + DEVTRACE("HouseKeeping() " << typeid(ptr).name()); (*ptr)(); delete ptr ; } while (it != GENERIC_DESTRUCTOR::Destructors->begin()) ; - cerr << "HouseKeeping() end list "<< endl; + DEVTRACE("HouseKeeping() end list "); GENERIC_DESTRUCTOR::Destructors->clear() ; assert(GENERIC_DESTRUCTOR::Destructors->size() == 0); assert(GENERIC_DESTRUCTOR::Destructors->empty()); - cerr << "HouseKeeping()after clear "<< endl; + DEVTRACE("HouseKeeping()after clear "); } delete GENERIC_DESTRUCTOR::Destructors; GENERIC_DESTRUCTOR::Destructors = 0; - cerr << "HouseKeeping() very end "<< endl; + DEVTRACE("HouseKeeping() very end "); return ; } @@ -160,18 +180,13 @@ void HouseKeeping( void ) const int GENERIC_DESTRUCTOR::Add(GENERIC_DESTRUCTOR &anObject) { - cerr << "GENERIC_DESTRUCTOR::Add("<begin(), Destructors->end(), &anObject) -// == Destructors->end()) -// { -// Destructors->push_back(&anObject); -// } Destructors->push_back(&anObject); return Destructors->size(); } diff --git a/src/Basics/BasicsGenericDestructor.hxx b/src/Basics/BasicsGenericDestructor.hxx index 607d849d4..a5d934dd8 100644 --- a/src/Basics/BasicsGenericDestructor.hxx +++ b/src/Basics/BasicsGenericDestructor.hxx @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include #if defined BASICS_EXPORTS @@ -49,6 +51,34 @@ #endif #endif +//#define _DEVDEBUG_ + +#ifdef _DEVDEBUG_ +#define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";} +#define DEVTRACE(msg) {MYDEVTRACE; std::cerr<= 0); } @@ -137,11 +167,7 @@ public: { if (_objectPtr) { - //TYPE* aPtr = static_cast(_objectPtr); - //std::cerr << "DESTRUCTOR_OF<" << typeid(*aPtr).name() - // << ">::operator() " << _objectPtr << " " << aPtr << endl; - //if (aPtr) PROTECTED_DELETE::deleteInstance(_objectPtr); - std::cerr << "DESTRUCTOR_OF<>::operator() " << _objectPtr << endl; + DEVTRACE("DESTRUCTOR_OF<>::operator() " << _objectPtr); if (_objectPtr) PROTECTED_DELETE::deleteInstance(_objectPtr); _objectPtr = NULL; } @@ -149,7 +175,7 @@ public: virtual ~DESTRUCTOR_OF() { - cerr << "~DESTRUCTOR_OF() " << this << endl; + DEVTRACE("~DESTRUCTOR_OF() " << this); assert(!_objectPtr); } diff --git a/src/SALOMELocalTrace/FileTraceCollector.cxx b/src/SALOMELocalTrace/FileTraceCollector.cxx index 6015c5070..5dd1074be 100644 --- a/src/SALOMELocalTrace/FileTraceCollector.cxx +++ b/src/SALOMELocalTrace/FileTraceCollector.cxx @@ -56,17 +56,17 @@ BaseTraceCollector* FileTraceCollector::instance(const char *fileName) ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone if (_singleton == 0) // another thread may have got { // the lock after the first test - //cerr << "FileTraceCollector:: instance()" << endl << flush; + DEVTRACE("FileTraceCollector:: instance()"); _singleton = new FileTraceCollector(); _fileName = fileName; - //cerr << " _fileName: " << _fileName << endl; + DEVTRACE(" _fileName: " << _fileName); pthread_t traceThread; int bid; int re2 = pthread_create(&traceThread, NULL, FileTraceCollector::run, (void *)bid); - //cerr << "FileTraceCollector:: instance()-end" << endl << flush; + DEVTRACE("FileTraceCollector:: instance()-end"); } ret = pthread_mutex_unlock(&_singletonMutex); // release lock } @@ -131,7 +131,7 @@ void* FileTraceCollector::run(void *bid) while ((!_threadToClose) || myTraceBuffer->toCollect() ) { if (_threadToClose) - cerr << "FileTraceCollector _threadToClose" << endl << flush; + DEVTRACE("FileTraceCollector _threadToClose"); int fullBuf = myTraceBuffer->retrieve(myTrace); if (myTrace.traceType == ABORT_MESS) @@ -167,9 +167,9 @@ void* FileTraceCollector::run(void *bid) #endif } } - cerr <<"traceFile.close();" << endl << flush; + DEVTRACE("traceFile.close()"); traceFile.close(); - cerr <<"traceFile.close()_end;" << endl << flush; + DEVTRACE("traceFile.close()_end"); pthread_exit(NULL); } //return NULL; @@ -187,7 +187,7 @@ FileTraceCollector:: ~FileTraceCollector() ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone if (_singleton) { - cerr << "FileTraceCollector:: ~FileTraceCollector()" << endl << flush; + DEVTRACE("FileTraceCollector:: ~FileTraceCollector()"); LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance(); _threadToClose = 1; myTraceBuffer->insert(NORMAL_MESS,"end of trace\n"); // to wake up thread @@ -195,7 +195,7 @@ FileTraceCollector:: ~FileTraceCollector() { int ret = pthread_join(*_threadId, NULL); if (ret) cerr << "error close FileTraceCollector : "<< ret << endl; - else cerr << "FileTraceCollector destruction OK" << endl; + else DEVTRACE("FileTraceCollector destruction OK"); _threadId = 0; _threadToClose = 0; } diff --git a/src/SALOMELocalTrace/LocalTraceBufferPool.cxx b/src/SALOMELocalTrace/LocalTraceBufferPool.cxx index bdc98695d..d875fe5be 100644 --- a/src/SALOMELocalTrace/LocalTraceBufferPool.cxx +++ b/src/SALOMELocalTrace/LocalTraceBufferPool.cxx @@ -285,14 +285,14 @@ LocalTraceBufferPool::~LocalTraceBufferPool() int ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone if (_singleton) { - cerr << "LocalTraceBufferPool::~LocalTraceBufferPool()" << endl<putMessage(LogMsg); - //cerr << " Logger server found" << endl; + DEVTRACE("Logger server found"); } // --- Loop until there is no more buffer to print, @@ -191,7 +191,7 @@ SALOMETraceCollector:: ~SALOMETraceCollector() ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone if (_singleton) { - //cerr << "SALOMETraceCollector:: ~SALOMETraceCollector()" <insert(NORMAL_MESS,"end of trace\n"); // to wake up thread @@ -199,7 +199,7 @@ SALOMETraceCollector:: ~SALOMETraceCollector() { int ret = pthread_join(*_threadId, NULL); if (ret) cerr << "error close SALOMETraceCollector : "<< ret << endl; - //else cerr << "SALOMETraceCollector destruction OK" << endl; + else DEVTRACE("SALOMETraceCollector destruction OK"); _threadId = 0; _threadToClose = 0; } -- 2.39.2