Salome HOME
[EDF29576] : Fix on debian10
[modules/kernel.git] / src / Basics / BasicsGenericDestructor.cxx
index 65464f6643929a1abd45ca0555f96b7c58cbddc8..a274b706f9d6acb4ae053c71dc309341b84f9707 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  SALOME Basics : general SALOME definitions and tools (C++ part - no CORBA)
 //  File   : BasicGenericDestructor.cxx
 //  Author : Antoine YESSAYAN, Paul RASCLE, EDF
@@ -31,8 +32,6 @@
 
 #include "BasicsGenericDestructor.hxx"
 
-using namespace std;
-
 void HouseKeeping();
 
 std::list<PROTECTED_DELETE*> PROTECTED_DELETE::_objList;
@@ -60,17 +59,16 @@ void PROTECTED_DELETE::deleteInstance(PROTECTED_DELETE *anObject)
       return;
     else
       {
-       int ret;
-       ret = pthread_mutex_lock(&_listMutex); // acquire lock, an check again
-       if (std::find(_objList.begin(), _objList.end(), anObject)
-           != _objList.end())
-         {
-           DEVTRACE("PROTECTED_DELETE::deleteInstance1 " << anObject);
-           delete anObject;
-           DEVTRACE("PROTECTED_DELETE::deleteInstance2 " << &_objList);
-           _objList.remove(anObject);
-         }
-       ret = pthread_mutex_unlock(&_listMutex); // release lock
+        pthread_mutex_lock(&_listMutex); // acquire lock, an check again
+        if (std::find(_objList.begin(), _objList.end(), anObject)
+            != _objList.end())
+          {
+            DEVTRACE("PROTECTED_DELETE::deleteInstance1 " << anObject);
+            delete anObject;
+            DEVTRACE("PROTECTED_DELETE::deleteInstance2 " << &_objList);
+            _objList.remove(anObject);
+          }
+        pthread_mutex_unlock(&_listMutex); // release lock
       }
   }
 
@@ -116,12 +114,16 @@ public:
   {
     if (Make_ATEXIT && !atExitSingletonDone)
       {
-       DEVTRACE("atExitSingleton(" << Make_ATEXIT << ")");
-       assert(GENERIC_DESTRUCTOR::Destructors == 0);
-       GENERIC_DESTRUCTOR::Destructors = new std::list<GENERIC_DESTRUCTOR*>;
-       int cr = atexit(HouseKeeping);
-       assert(cr == 0);
-       atExitSingletonDone = true;
+        DEVTRACE("atExitSingleton(" << Make_ATEXIT << ")");
+        assert(GENERIC_DESTRUCTOR::Destructors == 0);
+        GENERIC_DESTRUCTOR::Destructors = new std::list<GENERIC_DESTRUCTOR*>;
+#ifndef _DEBUG_
+        atexit(HouseKeeping);
+#else
+        int cr = atexit(HouseKeeping);
+        assert(cr == 0);
+#endif
+        atExitSingletonDone = true;
       }
   }
 
@@ -150,16 +152,16 @@ void HouseKeeping( void )
   if(GENERIC_DESTRUCTOR::Destructors->size())
     {
       std::list<GENERIC_DESTRUCTOR*>::iterator it =
-       GENERIC_DESTRUCTOR::Destructors->end();
+        GENERIC_DESTRUCTOR::Destructors->end();
 
       do
-       {
-         it-- ;
-         GENERIC_DESTRUCTOR* ptr = *it ;
-         DEVTRACE("HouseKeeping() " << typeid(ptr).name());
-         (*ptr)();
-         delete ptr ;
-       }
+        {
+          it-- ;
+          GENERIC_DESTRUCTOR* ptr = *it ;
+          DEVTRACE("HouseKeeping() " << typeid(ptr).name());
+          (*ptr)();
+          delete ptr ;
+        }
       while (it !=  GENERIC_DESTRUCTOR::Destructors->begin()) ;
 
       DEVTRACE("HouseKeeping() end list ");
@@ -183,15 +185,15 @@ void HouseKeeping( void )
  */
 // ============================================================================
 
-const int GENERIC_DESTRUCTOR::Add(GENERIC_DESTRUCTOR &anObject)
+int GENERIC_DESTRUCTOR::Add(GENERIC_DESTRUCTOR &anObject)
 {
   DEVTRACE("GENERIC_DESTRUCTOR::Add("<<typeid(anObject).name()<<") "
-          << &anObject);
+           << &anObject);
   if (!atExitSingletonDone)
     {
       HouseKeeper = atExitSingleton(true);
     }
   assert(Destructors);
   Destructors->push_back(&anObject);
-  return Destructors->size();
+  return (int)Destructors->size();
 }