swebb2066 commented on code in PR #148:
URL: https://github.com/apache/logging-log4cxx/pull/148#discussion_r1015945163
##########
src/main/cpp/messagebuffer.cpp:
##########
@@ -149,10 +118,14 @@ CharMessageBuffer& CharMessageBuffer::operator<<(const
char msg)
CharMessageBuffer::operator std::basic_ostream<char>& ()
{
- if (m_priv->stream == 0)
+ if (!m_priv->stream)
{
+#if LOG4CXX_HAS_THREAD_LOCAL
+ thread_local static std::basic_ostringstream<char> sStream;
+ m_priv->stream = &sStream;
+#else
m_priv->stream = new std::basic_ostringstream<char>();
-
+#endif
Review Comment:
> would it make sense to simply make `m_priv->stream` a `thread_local
`variable instead of holding a pointer
The `m_priv->stream` must be zero when logging only `std::string` or `char*
` to implement the static string logging optimization.
> looks like if two threads are logging at the same time they could both get
the same ostringstream
The `thread_local ` implementation should ensure the sSteam obtained by each
thread will be different, and the `m_priv->stream` pointer life-time is the
`MessageBuffer` lifetime. The only way two threads could share the same
`ostringstream` is if the user provides a `MessageBuffer` object reference to
the other thread. `MessageBuffer` is not intended to be used outside LOG4CXX_*
macros.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]