Skip to content

Commit

Permalink
Revert commits changing log4cplus mutexes to standard C++ mutexes.
Browse files Browse the repository at this point in the history
The reason we have the wrappers is also that it allows us to compile
a single threaded variant of log4cplus without the overhead of the
mutexes at run time. The wrappers have to stay for this reason.
  • Loading branch information
wilx committed Dec 22, 2023
1 parent 3d5c857 commit 8671e98
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 89 deletions.
8 changes: 4 additions & 4 deletions include/log4cplus/consoleappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace log4cplus {
* <dt><tt>ImmediateFlush</tt></dt>
* <dd>When it is set true, output stream will be flushed after
* each appended event.</dd>
*
*
* <dt><tt>Locale</tt></dt>
* <dd>This property specifies a locale name that will be imbued
* into output stream. Locale can be specified either by system
Expand All @@ -61,11 +61,11 @@ namespace log4cplus {
* <code>spi::LocaleFactory</code> in
* <code>spi::LocaleFactoryRegistry</code>.
* \sa spi::getLocaleFactoryRegistry().
*
*
* Note: if <tt>Locale</tt> is set, <tt>ImmediateFlush</tt> will
* be set to true automatically.
* </dd>
*
*
* </dl>
* \sa Appender
*/
Expand All @@ -83,7 +83,7 @@ namespace log4cplus {

//! This mutex is used by ConsoleAppender and helpers::LogLog
//! classes to synchronize output to console.
static std::recursive_mutex & getOutputMutex();
static log4cplus::thread::Mutex const & getOutputMutex();

protected:
virtual void append(const spi::InternalLoggingEvent& event);
Expand Down
16 changes: 8 additions & 8 deletions include/log4cplus/helpers/connectorthread.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// -*- C++ -*-
// Copyright (C) 2013-2017, Vaclav Zeman. All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without modifica-
// tion, are permitted provided that the following conditions are met:
//
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -51,7 +51,7 @@ class LOG4CPLUS_EXPORT IConnectorThreadClient

//! \return Mutex for synchronization between ConnectorThread and
//! its client object. This is usually SharedObject::access_mutex.
virtual std::recursive_mutex & ctcGetAccessMutex () const = 0;
virtual thread::Mutex const & ctcGetAccessMutex () const = 0;

//! \return Socket variable in ConnectorThread client to maintain.
virtual helpers::Socket & ctcGetSocket () = 0;
Expand All @@ -76,7 +76,7 @@ class LOG4CPLUS_EXPORT ConnectorThread
//! \param client reference to ConnectorThread's client object
ConnectorThread (IConnectorThreadClient & client);
virtual ~ConnectorThread ();

virtual void run();

//! Call this function to terminate ConnectorThread. The function
Expand All @@ -87,15 +87,15 @@ class LOG4CPLUS_EXPORT ConnectorThread
//! This function triggers (`trigger_ev`) connection check and
//! attempt to re-connect a broken connection, when necessary.
void trigger ();

protected:
//! reference to ConnectorThread's client
IConnectorThreadClient & ctc;

//! This event is the re-connection trigger.
thread::ManualResetEvent trigger_ev;

//! When this variable set to true when ConnectorThread is signaled to
//! When this variable set to true when ConnectorThread is signaled to
bool exit_flag;
};

Expand Down
4 changes: 2 additions & 2 deletions include/log4cplus/helpers/loglog.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace log4cplus {

/**
* In quite mode no LogLog generates strictly no output, not even
* for errors.
* for errors.
*
* @param quietMode A true for not
*/
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace log4cplus {
// Data
mutable TriState debugEnabled;
mutable TriState quietMode;
mutable std::mutex mutex;
thread::Mutex mutex;

LOG4CPLUS_PRIVATE LogLog(const LogLog&);
LOG4CPLUS_PRIVATE LogLog & operator = (LogLog const &);
Expand Down
2 changes: 1 addition & 1 deletion include/log4cplus/helpers/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace log4cplus {
SharedObject& operator=(SharedObject &&) LOG4CPLUS_NOEXCEPT { return *this; }

public:
mutable std::recursive_mutex access_mutex;
thread::Mutex access_mutex;

private:
#if defined (LOG4CPLUS_SINGLE_THREADED)
Expand Down
2 changes: 1 addition & 1 deletion include/log4cplus/socketappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace log4cplus
bool ipv6 = false;

#if ! defined (LOG4CPLUS_SINGLE_THREADED)
virtual std::recursive_mutex & ctcGetAccessMutex () const;
virtual thread::Mutex const & ctcGetAccessMutex () const;
virtual helpers::Socket & ctcGetSocket ();
virtual helpers::Socket ctcConnect ();
virtual void ctcSetConnected ();
Expand Down
6 changes: 3 additions & 3 deletions include/log4cplus/spi/objectregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ namespace log4cplus {
typedef std::map<log4cplus::tstring, void*> ObjectMap;

// Data
mutable std::mutex mutex;
thread::Mutex mutex;
ObjectMap data;

private:
ObjectRegistryBase (ObjectRegistryBase const &) = delete;
ObjectRegistryBase & operator = (ObjectRegistryBase const &) = delete;
ObjectRegistryBase (ObjectRegistryBase const &);
ObjectRegistryBase & operator = (ObjectRegistryBase const &);

bool volatile locking;
};
Expand Down
2 changes: 1 addition & 1 deletion include/log4cplus/syslogappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace log4cplus
void openSocket ();

#if ! defined (LOG4CPLUS_SINGLE_THREADED)
virtual std::recursive_mutex & ctcGetAccessMutex () const;
virtual thread::Mutex const & ctcGetAccessMutex () const;
virtual helpers::Socket & ctcGetSocket ();
virtual helpers::Socket ctcConnect ();
virtual void ctcSetConnected ();
Expand Down
14 changes: 7 additions & 7 deletions src/appender.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Appender::asyncDoAppend(const log4cplus::spi::InternalLoggingEvent& event)
void
Appender::syncDoAppend(const log4cplus::spi::InternalLoggingEvent& event)
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

if(closed) {
helpers::getLogLog().error(
Expand Down Expand Up @@ -434,7 +434,7 @@ Appender::setErrorHandler(std::unique_ptr<ErrorHandler> eh)
return;
}

std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

this->errorHandler = std::move(eh);
}
Expand All @@ -444,7 +444,7 @@ Appender::setErrorHandler(std::unique_ptr<ErrorHandler> eh)
void
Appender::setLayout(std::unique_ptr<Layout> lo)
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

this->layout = std::move(lo);
}
Expand All @@ -454,7 +454,7 @@ Appender::setLayout(std::unique_ptr<Layout> lo)
Layout*
Appender::getLayout()
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

return layout.get();
}
Expand All @@ -463,7 +463,7 @@ Appender::getLayout()
void
Appender::setFilter(log4cplus::spi::FilterPtr f)
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

filter = std::move (f);
}
Expand All @@ -472,7 +472,7 @@ Appender::setFilter(log4cplus::spi::FilterPtr f)
log4cplus::spi::FilterPtr
Appender::getFilter() const
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

return filter;
}
Expand All @@ -481,7 +481,7 @@ Appender::getFilter() const
void
Appender::addFilter (log4cplus::spi::FilterPtr f)
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

log4cplus::spi::FilterPtr filterChain = getFilter ();
if (filterChain)
Expand Down
10 changes: 5 additions & 5 deletions src/connectorthread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ConnectorThread::run ()
// Check exit condition as the very first thing.

{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);
if (exit_flag)
return;
trigger_ev.reset ();
Expand All @@ -68,9 +68,9 @@ ConnectorThread::run ()
// Do not try to re-open already open socket.

helpers::Socket & client_socket = ctc.ctcGetSocket ();
std::recursive_mutex & client_access_mutex = ctc.ctcGetAccessMutex ();
thread::Mutex const & client_access_mutex = ctc.ctcGetAccessMutex ();
{
std::lock_guard guard {client_access_mutex};
thread::MutexGuard guard (client_access_mutex);
if (client_socket.isOpen ())
continue;
}
Expand All @@ -95,7 +95,7 @@ ConnectorThread::run ()
// Connection was successful, move the socket into client.

{
std::lock_guard guard {client_access_mutex};
thread::MutexGuard guard (client_access_mutex);
client_socket = std::move (new_socket);
ctc.ctcSetConnected ();
}
Expand All @@ -107,7 +107,7 @@ void
ConnectorThread::terminate ()
{
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);
exit_flag = true;
trigger_ev.signal ();
}
Expand Down
8 changes: 4 additions & 4 deletions src/consoleappender.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ namespace log4cplus
namespace helpers
{

extern std::recursive_mutex & getConsoleOutputMutex ();
extern log4cplus::thread::Mutex const & getConsoleOutputMutex ();

} // namespace helpers


std::recursive_mutex &
log4cplus::thread::Mutex const &
ConsoleAppender::getOutputMutex ()
{
return helpers::getConsoleOutputMutex ();
Expand Down Expand Up @@ -93,7 +93,7 @@ ConsoleAppender::~ConsoleAppender()
// ConsoleAppender public methods
//////////////////////////////////////////////////////////////////////////////

void
void
ConsoleAppender::close()
{
helpers::getLogLog().debug(
Expand All @@ -110,7 +110,7 @@ ConsoleAppender::close()
void
ConsoleAppender::append(const spi::InternalLoggingEvent& event)
{
std::lock_guard guard {getOutputMutex ()};
thread::MutexGuard guard (getOutputMutex ());

tostream& output = (logToStdErr ? tcerr : tcout);

Expand Down
2 changes: 1 addition & 1 deletion src/fileappender.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ FileAppenderBase::init()
void
FileAppenderBase::close()
{
std::lock_guard guard {access_mutex};
thread::MutexGuard guard (access_mutex);

out.close();
buffer.reset ();
Expand Down
4 changes: 2 additions & 2 deletions src/global-init.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct ThreadPoolHolder
//! Default context.
struct DefaultContext
{
std::recursive_mutex console_mutex;
log4cplus::thread::Mutex console_mutex;
helpers::LogLog loglog;
LogLevelManager log_level_manager;
internal::CustomLogLevelManager custom_log_level_manager;
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace helpers
{


std::recursive_mutex &
log4cplus::thread::Mutex const &
getConsoleOutputMutex ()
{
return get_dc ()->console_mutex;
Expand Down
8 changes: 4 additions & 4 deletions src/loglog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ LogLog::~LogLog() = default;
void
LogLog::setInternalDebugging(bool enabled)
{
std::lock_guard guard {mutex};
thread::MutexGuard guard (mutex);

debugEnabled = enabled ? TriTrue : TriFalse;
}
Expand All @@ -69,7 +69,7 @@ LogLog::setInternalDebugging(bool enabled)
void
LogLog::setQuietMode(bool quietModeVal)
{
std::lock_guard guard {mutex};
thread::MutexGuard guard (mutex);

quietMode = quietModeVal ? TriTrue : TriFalse;
}
Expand Down Expand Up @@ -168,15 +168,15 @@ LogLog::logging_worker (tostream & os, bool (LogLog:: * cond) () const,
{
bool output;
{
std::lock_guard guard {mutex};
thread::MutexGuard guard (mutex);
output = (this->*cond) ();
}

if (LOG4CPLUS_UNLIKELY (output))
{
// XXX This is potential recursive lock of
// ConsoleAppender::outputMutex.
std::lock_guard outputGuard {ConsoleAppender::getOutputMutex ()};
thread::MutexGuard outputGuard (ConsoleAppender::getOutputMutex ());
os << prefix << msg << std::endl;
}

Expand Down
Loading

0 comments on commit 8671e98

Please sign in to comment.