boost::logging::writer::on_dedicated_thread< msg_type, base_type > Struct Template Reference

Performs all writes on a dedicated thread - very efficient and thread-safe. More...

Inheritance diagram for boost::logging::writer::on_dedicated_thread< msg_type, base_type >:
[legend]
Collaboration diagram for boost::logging::writer::on_dedicated_thread< msg_type, base_type >:
[legend]

List of all members.

Public Member Functions

void write_period_ms (int period_ms)
 Sets the write period : on the dedicated thread (in milliseconds).
void resume ()
 Resumes the writes, after a pause().
void pause ()
 Pauses the writes, so that you can manipulate the base object (the formatters/destinations, for instance).


Detailed Description

template<class msg_type, class base_type>
struct boost::logging::writer::on_dedicated_thread< msg_type, base_type >

Performs all writes on a dedicated thread - very efficient and thread-safe.

#include <boost/logging/writer/on_dedicated_thread.hpp>

Keeps locks in the worker threads to a minimum: whenever a message is logged, is put into a queue (this is how long the lock lasts). Then, a dedicated thread reads the queue, and processes the messages (applying formatters and destinations if needed).

Transforming a logger into on-dedicated-thread writer

To transform a logger into on-dedicated-thread (thread-safe) writer, simply specify on_dedicated_thread as the thread safety:

typedef logger_format_write< default_, default_, writer::threading::on_dedicated_thread > logger_type;

Of if you're using boost::logging::scenario::usage scenarios, specify speed for the logger::favor_ :

using namespace boost::logging::scenario::usage;
typedef use< ..., ..., ..., logger_::favor::speed> finder;



Transforming a writer into on-dedicated-thread writer

To transform a writer into on-dedicated-thread thread-safe writer, simply surround the writer with on_dedicated_thread:

Example:

typedef gather::ostream_like::return_str<> string;

// not thread-safe
logger< string, write_to_cout> g_l();

// thread-safe, on dedicated thread
logger< string, on_dedicated_thread<string,write_to_cout> > g_l();

You should note that a writer is not necessary a logger. It can be a destination, for instance. For example, you might have a destination where writing is time consuming, while writing to the rest of the destinations is very fast. You can choose to write to all but that destination on the current thread, and to that destination on a dedicated thread. (If you want to write to all destinations on a different thread, we can go back to transforming a logger...)


Member Function Documentation

template<class msg_type, class base_type>
void boost::logging::writer::on_dedicated_thread< msg_type, base_type >::pause (  )  [inline]

Pauses the writes, so that you can manipulate the base object (the formatters/destinations, for instance).

After this function has been called, you can be sure that the other (dedicated) thread is not writing any messagges. In other words, the other thread is not manipulating the base object (formatters/destinations, for instance), but you can do it.

FIXME allow a timeout as well


The documentation for this struct was generated from the following file:

Copyright John Torjo © 2007
Have a question/ suggestion/ comment? Send me feedback