Back to index

salome-kernel  6.5.0
LocalTraceBufferPool.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : Paul RASCLE (EDF)
00024 //  Module : KERNEL
00025 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/SALOMELocalTrace/LocalTraceBufferPool.hxx,v 1.6.30.2.12.1 2012-04-12 14:05:31 vsr Exp $
00026 //
00027 #ifndef _LOCALTRACEBUFFERPOOL_HXX_
00028 #define _LOCALTRACEBUFFERPOOL_HXX_
00029 
00030 #include "SALOME_LocalTrace.hxx"
00031 
00032 #define TRACE_BUFFER_SIZE 512  // number of entries in circular buffer
00033                                // must be power of 2
00034 #define MAX_TRACE_LENGTH 1024   // messages are truncated at this size
00035 
00036 #include <pthread.h>
00037 #include <semaphore.h>
00038 #include "BaseTraceCollector.hxx"
00039 #include "BasicsGenericDestructor.hxx"
00040 
00041 #define ABORT_MESS  1   // for traceType field in struct LocalTrace_TraceInfo
00042 #define NORMAL_MESS 0
00043 
00044 struct SALOMELOCALTRACE_EXPORT LocalTrace_TraceInfo
00045 {
00046   char trace[MAX_TRACE_LENGTH];
00047   pthread_t threadId;
00048   int traceType;                 // normal or abort
00049   int position;                  // to check sequence
00050 };
00051 
00052 class SALOMELOCALTRACE_EXPORT LocalTraceBufferPool : public PROTECTED_DELETE
00053 {
00054  public:
00055   static LocalTraceBufferPool* instance();
00056   int insert(int traceType, const char* msg);
00057   int retrieve(LocalTrace_TraceInfo& aTrace);
00058   unsigned long toCollect();
00059 
00060  protected:
00061   LocalTraceBufferPool();
00062   virtual ~LocalTraceBufferPool();
00063   unsigned long lockedIncrement(unsigned long& pos);
00064 
00065  private:
00066   static LocalTraceBufferPool* _singleton;
00067   static pthread_mutex_t _singletonMutex;
00068   static BaseTraceCollector *_myThreadTrace;
00069 
00070   LocalTrace_TraceInfo _myBuffer[TRACE_BUFFER_SIZE];
00071   sem_t _freeBufferSemaphore;       // to wait until there is a free buffer
00072   sem_t _fullBufferSemaphore;       // to wait until there is a buffer to print
00073   pthread_mutex_t _incrementMutex;  // to lock position variables for increment
00074   unsigned long _position;
00075   unsigned long _insertPos;
00076   unsigned long _retrievePos;
00077 };
00078 
00079 #endif