1 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 // Author : Paul RASCLE (EDF)
24 #ifndef _LOCALTRACEBUFFERPOOL_HXX_
25 #define _LOCALTRACEBUFFERPOOL_HXX_
27 #define TRACE_BUFFER_SIZE 256 // number of entries in circular buffer
29 #define MAX_TRACE_LENGTH 256 // messages are truncated at this size
32 #include <semaphore.h>
34 #define ABORT_MESS 1 // for traceType field in struct LocalTrace_TraceInfo
37 #if defined SALOMELOCALTRACE_EXPORTS
39 #define SALOMELOCALTRACE_EXPORT __declspec( dllexport )
41 #define SALOMELOCALTRACE_EXPORT
45 #define SALOMELOCALTRACE_EXPORT __declspec( dllimport )
47 #define SALOMELOCALTRACE_EXPORT
53 struct SALOMELOCALTRACE_EXPORT LocalTrace_TraceInfo
55 char trace[MAX_TRACE_LENGTH];
57 int traceType; // normal or abort
58 int position; // to check sequence
61 class SALOMELOCALTRACE_EXPORT LocalTraceBufferPool
64 static LocalTraceBufferPool* instance();
65 int insert(int traceType, const char* msg);
66 int retrieve(LocalTrace_TraceInfo& aTrace);
67 unsigned long toCollect();
68 ~LocalTraceBufferPool();
71 LocalTraceBufferPool();
72 unsigned long lockedIncrement(unsigned long& pos);
75 static LocalTraceBufferPool* _singleton;
76 static pthread_mutex_t _singletonMutex;
77 LocalTrace_TraceInfo _myBuffer[TRACE_BUFFER_SIZE];
78 sem_t _freeBufferSemaphore; // to wait until there is a free buffer
79 sem_t _fullBufferSemaphore; // to wait until there is a buffer to print
80 pthread_mutex_t _incrementMutex; // to lock position variables for increment
81 unsigned long _position;
82 unsigned long _insertPos;
83 unsigned long _retrievePos;