Version: 8.3.0
LocalTraceBufferPool Class Reference

#include <LocalTraceBufferPool.hxx>

Inheritance diagram for LocalTraceBufferPool:

Public Member Functions

int insert (int traceType, const char *msg)
 Called by trace producers within their threads. More...
 
int retrieve (LocalTrace_TraceInfo &aTrace)
 Called by the thread in charge of printing trace messages. More...
 
unsigned long toCollect ()
 Gives the number of buffers to print. More...
 

Static Public Member Functions

static LocalTraceBufferPoolinstance ()
 Guarantees a unique object instance of the class (singleton thread safe). More...
 
static void deleteInstance (PROTECTED_DELETE *anObject)
 deleteInstance deletes only once the object. More...
 
static void addObj (PROTECTED_DELETE *anObject)
 To allow a further destruction of a PRTECTED_DELETE object, it must be added to the static list of PROTECTED_DELETE*. More...
 

Protected Member Functions

 LocalTraceBufferPool ()
 Constructor : initialize pool of buffers, semaphores and mutex. More...
 
virtual ~LocalTraceBufferPool ()
 Destructor : release memory associated with semaphores and mutex. More...
 
unsigned long lockedIncrement (unsigned long &pos)
 pool counters are incremented under a mutex protection More...
 

Static Protected Attributes

static std::list
< PROTECTED_DELETE * > 
_objList
 

Private Attributes

LocalTrace_TraceInfo _myBuffer [512]
 
sem_t _freeBufferSemaphore
 
sem_t _fullBufferSemaphore
 
pthread_mutex_t _incrementMutex
 
unsigned long _position
 
unsigned long _insertPos
 
unsigned long _retrievePos
 

Static Private Attributes

static LocalTraceBufferPool_singleton = 0
 
static pthread_mutex_t _singletonMutex
 
static BaseTraceCollector_myThreadTrace = 0
 

Constructor & Destructor Documentation

LocalTraceBufferPool::LocalTraceBufferPool ( )
protected

Constructor : initialize pool of buffers, semaphores and mutex.

References _freeBufferSemaphore, _fullBufferSemaphore, _incrementMutex, _insertPos, _myBuffer, _position, _retrievePos, IMMEDIATE_ABORT, MAXMESS_LENGTH, TRACE_BUFFER_SIZE, and TRUNCATED_MESSAGE.

Referenced by instance().

LocalTraceBufferPool::~LocalTraceBufferPool ( )
protectedvirtual

Destructor : release memory associated with semaphores and mutex.

References _freeBufferSemaphore, _fullBufferSemaphore, _incrementMutex, _myThreadTrace, _singleton, _singletonMutex, and DEVTRACE.

Member Function Documentation

void PROTECTED_DELETE::addObj ( PROTECTED_DELETE anObject)
staticinherited

To allow a further destruction of a PRTECTED_DELETE object, it must be added to the static list of PROTECTED_DELETE*.

References PROTECTED_DELETE::_objList, and DEVTRACE.

Referenced by DESTRUCTOR_OF< TYPE >::DESTRUCTOR_OF().

void PROTECTED_DELETE::deleteInstance ( PROTECTED_DELETE anObject)
staticinherited
int LocalTraceBufferPool::insert ( int  traceType,
const char msg 
)

Called by trace producers within their threads.

The trace message is copied in specific buffer from a circular pool of buffers. Waits until there is a free buffer in the pool, gets the first available buffer, fills it with the message. Messages are printed in a separate thread (see retrieve method)

References _freeBufferSemaphore, _fullBufferSemaphore, _insertPos, _myBuffer, _position, lockedIncrement(), MAXMESS_LENGTH, LocalTrace_TraceInfo::position, LocalTrace_TraceInfo::threadId, TRACE_BUFFER_SIZE, LocalTrace_TraceInfo::traceType, and traceType.

Referenced by FileTraceCollector::~FileTraceCollector(), LocalTraceCollector::~LocalTraceCollector(), and SALOMETraceCollector::~SALOMETraceCollector().

LocalTraceBufferPool * LocalTraceBufferPool::instance ( )
static

Guarantees a unique object instance of the class (singleton thread safe).

When the LocalTraceBufferPool instance is created, the trace collector is also created (singleton). Type of trace collector to create depends on environment variable "SALOME_trace":

  • "local" implies standard err trace, LocalTraceCollector is launched.
  • "file" implies trace in /tmp/tracetest.log
  • "file:pathname" implies trace in file pathname
  • anything else like "other" : try to load dynamically a library named otherTraceCollector, and invoque C method instance() to start a singleton instance of the trace collector. Example: with_loggerTraceCollector, for CORBA Log.

References _myThreadTrace, _singleton, _singletonMutex, DEVTRACE, LocalTraceCollector::instance(), FileTraceCollector::instance(), and LocalTraceBufferPool().

Referenced by ATEXIT_::ATEXIT_(), LocalTraceCollector::run(), FileTraceCollector::run(), SALOMETraceCollector::run(), UtilsTest::setUp(), LifeCycleCORBATest::setUp(), NamingServiceTest::setUp(), UtilsTest::tearDown(), LifeCycleCORBATest::tearDown(), NamingServiceTest::tearDown(), SALOMETraceCollectorTest::testLoadBufferPoolCORBA(), SALOMELocalTraceTest::testLoadBufferPoolFile(), SALOMELocalTraceTest::testLoadBufferPoolLocal(), SALOMELocalTraceTest::testSingletonBufferPool(), FileTraceCollector::~FileTraceCollector(), LocalTraceCollector::~LocalTraceCollector(), and SALOMETraceCollector::~SALOMETraceCollector().

unsigned long LocalTraceBufferPool::lockedIncrement ( unsigned long &  pos)
protected

pool counters are incremented under a mutex protection

References _incrementMutex.

Referenced by insert(), and retrieve().

int LocalTraceBufferPool::retrieve ( LocalTrace_TraceInfo aTrace)

Called by the thread in charge of printing trace messages.

Waits until there is a buffer with a message to print. Gets the first buffer to print, copies it int the provided buffer

References _freeBufferSemaphore, _fullBufferSemaphore, _myBuffer, _retrievePos, lockedIncrement(), MESSAGE, and TRACE_BUFFER_SIZE.

Referenced by LocalTraceCollector::run(), FileTraceCollector::run(), and SALOMETraceCollector::run().

unsigned long LocalTraceBufferPool::toCollect ( )

Gives the number of buffers to print.

Usage : when the thread in charge of messages print id to be stopped, check if there is still something to print, before stop. There is no need of mutex here, provided there is only one thread to retrieve and print the buffers.

References _insertPos, and _retrievePos.

Referenced by LocalTraceCollector::run(), FileTraceCollector::run(), and SALOMETraceCollector::run().

Field Documentation

sem_t LocalTraceBufferPool::_freeBufferSemaphore
private
sem_t LocalTraceBufferPool::_fullBufferSemaphore
private
pthread_mutex_t LocalTraceBufferPool::_incrementMutex
private
unsigned long LocalTraceBufferPool::_insertPos
private
LocalTrace_TraceInfo LocalTraceBufferPool::_myBuffer[512]
private
BaseTraceCollector * LocalTraceBufferPool::_myThreadTrace = 0
staticprivate

Referenced by instance(), and ~LocalTraceBufferPool().

std::list< PROTECTED_DELETE * > PROTECTED_DELETE::_objList
staticprotectedinherited
unsigned long LocalTraceBufferPool::_position
private

Referenced by insert(), and LocalTraceBufferPool().

unsigned long LocalTraceBufferPool::_retrievePos
private
LocalTraceBufferPool * LocalTraceBufferPool::_singleton = 0
staticprivate

Referenced by instance(), and ~LocalTraceBufferPool().

pthread_mutex_t LocalTraceBufferPool::_singletonMutex
staticprivate
Initial value:
=
PTHREAD_MUTEX_INITIALIZER

Referenced by instance(), and ~LocalTraceBufferPool().