Flow 2.0.0
Flow project: Full implementation reference.
Public Member Functions | Private Attributes | List of all members
flow::log::Log_context_mt Class Reference

Identical to Log_context but is safe w/r/t to set_logger(), assignment, and swap() done concurrently to ops (especially get_logger()) on the same *this. More...

#include <log.hpp>

Inheritance diagram for flow::log::Log_context_mt:
[legend]
Collaboration diagram for flow::log::Log_context_mt:
[legend]

Public Member Functions

 Log_context_mt (Logger *logger=nullptr)
 Identical to Log_context API. More...
 
template<typename Component_payload >
 Log_context_mt (Logger *logger, Component_payload component_payload)
 Identical to Log_context API. More...
 
 Log_context_mt (const Log_context_mt &src)
 Identical to Log_context API. More...
 
 Log_context_mt (Log_context_mt &&src)
 Identical to Log_context API. More...
 
Log_context_mtoperator= (const Log_context_mt &src)
 Identical to Log_context API; but safe against concurrent operations on a *this. More...
 
Log_context_mtoperator= (Log_context_mt &&src)
 Identical to Log_context API; but safe against concurrent operations on a *this. More...
 
void swap (Log_context_mt &other)
 Identical to Log_context API; but safe against concurrent operations on a *this. More...
 
Loggerget_logger () const
 Identical to Log_context API; but safe against concurrent operations on a *this. More...
 
Loggerset_logger (Logger *logger)
 Identical to Log_context API; but safe against concurrent operations on a *this. More...
 
const Componentget_log_component () const
 Identical to Log_context API. More...
 

Private Attributes

util::Mutex_non_recursive m_mutex
 Protects access to data in static_cast<Log_context&>(*this) (especially Log_context::m_logger). More...
 

Additional Inherited Members

- Private Member Functions inherited from flow::log::Log_context
 Log_context (Logger *logger=nullptr)
 Constructs Log_context by storing the given pointer to a Logger and a null Component. More...
 
template<typename Component_payload >
 Log_context (Logger *logger, Component_payload component_payload)
 Constructs Log_context by storing the given pointer to a Logger and a new Component storing the specified generically typed payload (an enum value). More...
 
 Log_context (const Log_context &src)
 Copy constructor that stores equal Logger* and Component values as the source. More...
 
 Log_context (Log_context &&src)
 Move constructor that makes this equal to src, while the latter becomes as-if default-constructed. More...
 
Log_contextoperator= (const Log_context &src)
 Assignment operator that behaves similarly to the copy constructor. More...
 
Log_contextoperator= (Log_context &&src)
 Move assignment operator that behaves similarly to the move constructor. More...
 
void swap (Log_context &other)
 Swaps Logger pointers and Component objects held by *this and other. More...
 
Loggerget_logger () const
 Returns the stored Logger pointer, particularly as many FLOW_LOG_*() macros expect. More...
 
Loggerset_logger (Logger *logger)
 Sets the value to be returned by the next get_logger() call; returns get_logger() from before the change. More...
 
const Componentget_log_component () const
 Returns reference to the stored Component object, particularly as many FLOW_LOG_*() macros expect. More...
 

Detailed Description

Identical to Log_context but is safe w/r/t to set_logger(), assignment, and swap() done concurrently to ops (especially get_logger()) on the same *this.

See also
Log_context doc header section "Setting the logger / thready safety."

There is a perf trade-off: essentially all operations will lock an internal mutex, proceed, then unlock. This will have a small cost when there is no lock contention (no simultaneous logging – get_logger() calls); and a larger cost when there is (when indeed there is simultaneous logging – therefore get_logger() calls). Informally: in our experience, as noted in the aforementioned doc header discussion, set_logger() is mainly used when the sub-class is instantiated statically or globally; and usually it is possible to simply avoid logging along fast-paths of such classes.

Still: it requires care. If you need to provide/use set_logger(), be mindful of this potential source of slow-down.

Definition at line 1772 of file log.hpp.

Constructor & Destructor Documentation

◆ Log_context_mt() [1/4]

flow::log::Log_context_mt::Log_context_mt ( Logger logger = nullptr)
explicit

Identical to Log_context API.

Parameters
loggerSee above.

Definition at line 246 of file log.cpp.

◆ Log_context_mt() [2/4]

template<typename Component_payload >
flow::log::Log_context_mt::Log_context_mt ( Logger logger,
Component_payload  component_payload 
)
explicit

Identical to Log_context API.

Template Parameters
Component_payloadSee above.
Parameters
loggerSee above.
component_payloadSee above.

Definition at line 1906 of file log.hpp.

◆ Log_context_mt() [3/4]

flow::log::Log_context_mt::Log_context_mt ( const Log_context_mt src)
explicit

Identical to Log_context API.

Parameters
srcSee above.

Definition at line 252 of file log.cpp.

References m_mutex, and flow::log::Log_context::operator=().

Here is the call graph for this function:

◆ Log_context_mt() [4/4]

flow::log::Log_context_mt::Log_context_mt ( Log_context_mt &&  src)

Identical to Log_context API.

Parameters
srcSee above.

Definition at line 260 of file log.cpp.

References m_mutex, swap(), and flow::log::swap().

Here is the call graph for this function:

Member Function Documentation

◆ get_log_component()

const Component & flow::log::Log_context_mt::get_log_component ( ) const

Identical to Log_context API.

Returns
See above.

Definition at line 333 of file log.cpp.

References flow::log::Log_context::get_log_component(), and m_mutex.

Here is the call graph for this function:

◆ get_logger()

Logger * flow::log::Log_context_mt::get_logger ( ) const

Identical to Log_context API; but safe against concurrent operations on a *this.

Returns
See above.

Definition at line 321 of file log.cpp.

References flow::log::Log_context::get_logger(), and m_mutex.

Here is the call graph for this function:

◆ operator=() [1/2]

Log_context_mt & flow::log::Log_context_mt::operator= ( const Log_context_mt src)

Identical to Log_context API; but safe against concurrent operations on a *this.

Parameters
srcSee above.
Returns
See above.

Definition at line 271 of file log.cpp.

References m_mutex, and flow::log::Log_context::operator=().

Here is the call graph for this function:

◆ operator=() [2/2]

Log_context_mt & flow::log::Log_context_mt::operator= ( Log_context_mt &&  src)

Identical to Log_context API; but safe against concurrent operations on a *this.

Parameters
srcSee above.
Returns
See above.

Definition at line 298 of file log.cpp.

References m_mutex, flow::log::Log_context::operator=(), swap(), and flow::log::swap().

Here is the call graph for this function:

◆ set_logger()

Logger * flow::log::Log_context_mt::set_logger ( Logger logger)

Identical to Log_context API; but safe against concurrent operations on a *this.

Parameters
loggerSee above.
Returns
See above.

Definition at line 327 of file log.cpp.

References m_mutex, and flow::log::Log_context::set_logger().

Here is the call graph for this function:

◆ swap()

void flow::log::Log_context_mt::swap ( Log_context_mt other)

Identical to Log_context API; but safe against concurrent operations on a *this.

Parameters
otherSee above.

Definition at line 339 of file log.cpp.

References m_mutex, swap(), and flow::log::swap().

Referenced by Log_context_mt(), operator=(), swap(), and flow::log::swap().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_mutex

util::Mutex_non_recursive flow::log::Log_context_mt::m_mutex
mutableprivate

Protects access to data in static_cast<Log_context&>(*this) (especially Log_context::m_logger).

Definition at line 1861 of file log.hpp.

Referenced by get_log_component(), get_logger(), Log_context_mt(), operator=(), set_logger(), and swap().


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