Commit 2caf9ff6 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2198] Use a mutex from LoggerManager during logging calls

... for mutual exclusion among threads.
parent 50b124ae
......@@ -48,5 +48,7 @@ if USE_CLANGPP
libb10_log_la_CXXFLAGS += -Wno-error
endif
libb10_log_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
libb10_log_la_LIBADD = $(top_builddir)/src/lib/util/libb10-util.la $(LOG4CPLUS_LIBS)
libb10_log_la_LIBADD = $(top_builddir)/src/lib/util/libb10-util.la
libb10_log_la_LIBADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
libb10_log_la_LIBADD += $(LOG4CPLUS_LIBS)
libb10_log_la_LDFLAGS = -no-undefined -version-info 1:0:0
......@@ -29,6 +29,7 @@
#include <log/logger_level.h>
#include <log/logger_level_impl.h>
#include <log/logger_name.h>
#include <log/logger_manager.h>
#include <log/message_dictionary.h>
#include <log/message_types.h>
......@@ -123,9 +124,12 @@ LoggerImpl::setInterprocessSync(isc::util::InterprocessSync* sync) {
void
LoggerImpl::outputRaw(const Severity& severity, const string& message) {
// Use a mutex locker for mutual exclusion from other threads in
// this process.
isc::util::thread::Mutex::Locker mutex_locker(LoggerManager::getMutex());
// Use an interprocess sync locker for mutual exclusion from other
// processes to avoid log messages getting interspersed.
InterprocessSyncLocker locker(*sync_);
if (!locker.lock()) {
......
......@@ -138,6 +138,9 @@ LoggerManager::init(const std::string& root, isc::log::Severity severity,
if (file) {
readLocalMessageFile(file);
}
// Ensure that the mutex is constructed and ready at this point.
(void) getMutex();
}
......@@ -192,5 +195,12 @@ LoggerManager::reset() {
LoggerManagerImpl::reset(initSeverity(), initDebugLevel());
}
isc::util::thread::Mutex&
LoggerManager::getMutex() {
static isc::util::thread::Mutex mutex;
return (mutex);
}
} // namespace log
} // namespace isc
......@@ -16,6 +16,7 @@
#define LOGGER_MANAGER_H
#include "exceptions/exceptions.h"
#include <util/threads/sync.h>
#include <log/logger_specification.h>
// Generated if, when updating the logging specification, an unknown
......@@ -132,6 +133,11 @@ public:
/// \param file Name of the local message file
static void readLocalMessageFile(const char* file);
/// \brief Return a process-global mutex that's used for mutual
/// exclusion among threads of a single process during logging
/// calls.
static isc::util::thread::Mutex& getMutex();
private:
/// \brief Initialize Processing
///
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment