Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::ThreadSafeLogStreamBuf Class Reference

This class implements a threadsafe version of the POCO buffer interface to a Logger's stream object. More...

#include <ThreadSafeLogStream.h>

Inheritance diagram for Mantid::Kernel::ThreadSafeLogStreamBuf:

Public Member Functions

void accumulate (const std::string &message)
 accumulate a message to the thread safe accummulator. More...
 
std::string flush ()
 Returns and flushes the accumulated message. More...
 
int overflow (char c)
 
 ThreadSafeLogStreamBuf (Poco::Logger &logger, Poco::Message::Priority priority)
 Constructor. More...
 

Private Member Functions

int writeToDevice (char c) override
 Overridden from base to write to the device in a thread-safe manner. More...
 

Private Attributes

std::map< Poco::Thread::TID, std::string > m_accumulator
 Store a map of thread indices to accummulators of messages. More...
 
std::map< Poco::Thread::TID, std::string > m_messages
 Store a map of thread indices to messages. More...
 
std::mutex m_mutex
 mutex protecting logstream More...
 

Detailed Description

This class implements a threadsafe version of the POCO buffer interface to a Logger's stream object.

The buffer uses OpenMP API calls to both protect shared memory from access by multiple threads and updates log messages is such a way that they are not mangled by separate threads.

Author
Martyn Gigg, Tessella Support Services plc
Date
13/04/2010

Definition at line 41 of file ThreadSafeLogStream.h.

Constructor & Destructor Documentation

◆ ThreadSafeLogStreamBuf()

ThreadSafeLogStreamBuf::ThreadSafeLogStreamBuf ( Poco::Logger &  logger,
Poco::Message::Priority  priority 
)

Constructor.

Definition at line 25 of file ThreadSafeLogStream.cpp.

Member Function Documentation

◆ accumulate()

void ThreadSafeLogStreamBuf::accumulate ( const std::string &  message)

accumulate a message to the thread safe accummulator.

Parameters
message:: The log message

Definition at line 53 of file ThreadSafeLogStream.cpp.

References m_accumulator, and m_mutex.

Referenced by Mantid::Kernel::ThreadSafeLogStream::accumulate().

◆ flush()

std::string ThreadSafeLogStreamBuf::flush ( )

Returns and flushes the accumulated message.

Returns
The accumulated message

Definition at line 62 of file ThreadSafeLogStream.cpp.

References m_accumulator, and m_mutex.

Referenced by Mantid::Kernel::ThreadSafeLogStream::flush().

◆ overflow()

int ThreadSafeLogStreamBuf::overflow ( char  c)

Definition at line 28 of file ThreadSafeLogStream.cpp.

◆ writeToDevice()

int ThreadSafeLogStreamBuf::writeToDevice ( char  c)
overrideprivate

Overridden from base to write to the device in a thread-safe manner.

If the character is an EOL character then write the buffered messsage to the chosen device(s).

If not, buffer the character

Parameters
c:: The input character
Returns
The ASCII code of the input character

Definition at line 37 of file ThreadSafeLogStream.cpp.

References m_messages, and m_mutex.

Member Data Documentation

◆ m_accumulator

std::map<Poco::Thread::TID, std::string> Mantid::Kernel::ThreadSafeLogStreamBuf::m_accumulator
private

Store a map of thread indices to accummulators of messages.

Definition at line 58 of file ThreadSafeLogStream.h.

Referenced by accumulate(), and flush().

◆ m_messages

std::map<Poco::Thread::TID, std::string> Mantid::Kernel::ThreadSafeLogStreamBuf::m_messages
private

Store a map of thread indices to messages.

Definition at line 56 of file ThreadSafeLogStream.h.

Referenced by writeToDevice().

◆ m_mutex

std::mutex Mantid::Kernel::ThreadSafeLogStreamBuf::m_mutex
private

mutex protecting logstream

Definition at line 60 of file ThreadSafeLogStream.h.

Referenced by accumulate(), flush(), and writeToDevice().


The documentation for this class was generated from the following files: