Salome HOME
First stable version after merging with V3_2_2
[modules/kernel.git] / src / SALOMELocalTrace / LocalTraceBufferPool.cxx
index 4523a897dfc5d02d1de9d62ef68bcba57b43d697..c9aa338dccecec1d0c7bab6289a779c96f1af22a 100644 (file)
@@ -15,7 +15,7 @@
 //  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  Author : Paul RASCLE (EDF)
 //  Module : KERNEL
@@ -31,6 +31,7 @@
 #ifndef WNT
 #include <dlfcn.h>
 #else
+#include <windows.h>
 #endif
 
 //#define _DEVDEBUG_
@@ -51,12 +52,12 @@ using namespace std;
 // Class static attributes initialisation
 
 LocalTraceBufferPool* LocalTraceBufferPool::_singleton = 0;
-#ifndef WNT
-pthread_mutex_t LocalTraceBufferPool::_singletonMutex;
-#else
+//#ifndef WNT
+//pthread_mutex_t LocalTraceBufferPool::_singletonMutex;
+//#else
 pthread_mutex_t LocalTraceBufferPool::_singletonMutex =
   PTHREAD_MUTEX_INITIALIZER;
-#endif
+//#endif
 BaseTraceCollector *LocalTraceBufferPool::_myThreadTrace = 0;
 
 // ============================================================================
@@ -112,27 +113,33 @@ LocalTraceBufferPool* LocalTraceBufferPool::instance()
            }
          else // --- try a dynamic library
            {
-             void* handle;
 #ifndef WNT
+             void* handle;
              string impl_name = string ("lib") + traceKind 
                + string("TraceCollector.so");
              handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ;
 #else
+             HINSTANCE handle;
              string impl_name = string ("lib") + traceKind + string(".dll");
-             handle = dlopen( impl_name.c_str() , 0 ) ;
+             handle = LoadLibrary( impl_name.c_str() );
 #endif
              if ( handle )
                {
                  typedef BaseTraceCollector * (*FACTORY_FUNCTION) (void);
+#ifndef WNT
                  FACTORY_FUNCTION TraceCollectorFactory =
                    (FACTORY_FUNCTION) dlsym(handle, "SingletonInstance");
-                 char *error ;
-                 if ( (error = dlerror() ) != NULL)
-                   {
+#else
+                 FACTORY_FUNCTION TraceCollectorFactory =
+                   (FACTORY_FUNCTION)GetProcAddress(handle, "SingletonInstance");
+#endif
+                 if ( !TraceCollectorFactory )
+                 {
                      cerr << "Can't resolve symbol: SingletonInstance" <<endl;
-                     cerr << "dlerror: " << error << endl;
-                     assert(error == NULL); // to give file and line
-                     exit(1);               // in case assert is deactivated
+#ifndef WNT
+                     cerr << "dlerror: " << dlerror() << endl;
+#endif
+                     exit( 1 );
                    }
                  _myThreadTrace = (TraceCollectorFactory) ();
                }
@@ -169,7 +176,12 @@ int LocalTraceBufferPool::insert(int traceType, const char* msg)
 
   // wait until there is a free buffer in the pool
 
-  int ret = sem_wait(&_freeBufferSemaphore);
+  int ret = -1;
+  while (ret)
+    {
+      ret = sem_wait(&_freeBufferSemaphore);
+      if (ret) perror(" LocalTraceBufferPool::insert, sem_wait");
+    }
 
   // get the next free buffer available (mutex protected) 
 
@@ -209,7 +221,12 @@ int LocalTraceBufferPool::retrieve(LocalTrace_TraceInfo& aTrace)
 
   // wait until there is a buffer in the pool, with a message to print
 
-  int ret = sem_wait(&_fullBufferSemaphore);
+  int ret = -1;
+  while (ret)
+    {
+      ret = sem_wait(&_fullBufferSemaphore);
+      if (ret) perror(" LocalTraceBufferPool::retrieve, sem_wait");
+    }
 
   // get the next buffer to print