From 094e4ab92fb9dadc307167a09d1c0be7ab4706d0 Mon Sep 17 00:00:00 2001 From: mkhan Date: Tue, 3 Apr 2018 10:12:00 +1000 Subject: [PATCH] closes #580 conditional global lock --- CHANGELOG.md | 4 ++++ CMakeLists.txt | 2 +- README.md | 1 + samples/STL/compile.sh | 1 + src/easylogging++.cc | 6 ++++++ src/easylogging++.h | 2 +- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91de75e30..2d958fe1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [9.96.4] - 03-04-2018 +### Fixes +- Fixes seg fault with global lock (issue #580) + ## [9.96.3] - 01-04-2018 ### Fixes - Demangling in GCC fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b0fa63e9..506b59f2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ option(lib_utc_datetime "Build library with UTC date/time logging" OFF) set(ELPP_MAJOR_VERSION "9") set(ELPP_MINOR_VERSION "96") -set(ELPP_PATCH_VERSION "3") +set(ELPP_PATCH_VERSION "4") set(ELPP_VERSION_STRING "${ELPP_MAJOR_VERSION}.${ELPP_MINOR_VERSION}.${ELPP_PATCH_VERSION}") set(ELPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") diff --git a/README.md b/README.md index 8b95c1edb..4dfc85295 100644 --- a/README.md +++ b/README.md @@ -520,6 +520,7 @@ Some of logging options can be set by macros, this is a thoughtful decision, for | `ELPP_NO_CHECK_MACROS` | Do not define the *CHECK* macros | | `ELPP_NO_DEBUG_MACROS` | Do not define the *DEBUG* macros | | `ELPP_UTC_DATETIME` | Uses UTC time instead of local time (essentially uses `gmtime` instead of `localtime` and family functions) +| `ELPP_NO_GLOBAL_LOCK` | Do not lock the whole storage on dispatch. This should be used with care. See [issue #580](https://github.com/muflihun/easyloggingpp/issues/580)| [![top] Goto Top](#table-of-contents) diff --git a/samples/STL/compile.sh b/samples/STL/compile.sh index 2c7f3f7d4..3a75d57da 100755 --- a/samples/STL/compile.sh +++ b/samples/STL/compile.sh @@ -10,6 +10,7 @@ macro="$macro -DELPP_LOG_UNORDERED_MAP" macro="$macro -DELPP_FEATURE_CRASH_LOG" macro="$macro -DELPP_LOGGING_FLAGS_FROM_ARG" macro="$macro -DELPP_FEATURE_ALL" +macro="$macro -DELPP_NO_GLOBAL_LOCK" # macro="$macro -DELPP_DEFAULT_LOG_FILE=\"/a/path/that/does/not/exist/f.log\"" if [ "$2" = "" ];then diff --git a/src/easylogging++.cc b/src/easylogging++.cc index 83faacbb7..b6a450381 100644 --- a/src/easylogging++.cc +++ b/src/easylogging++.cc @@ -2473,6 +2473,12 @@ void LogDispatcher::dispatch(void) { if (!m_proceed) { return; } +#ifndef ELPP_NO_GLOBAL_LOCK + // see https://github.com/muflihun/easyloggingpp/issues/580 + // global lock is turned off by default unless + // ELPP_NO_GLOBAL_LOCK is defined + base::threading::ScopedLock scopedLock(ELPP->lock()); +#endif base::TypedConfigurations* tc = m_logMessage->logger()->m_typedConfigurations; if (ELPP->hasFlag(LoggingFlag::StrictLogFileSizeCheck)) { tc->validateFileRolling(m_logMessage->level(), ELPP->preRollOutCallback()); diff --git a/src/easylogging++.h b/src/easylogging++.h index 1b8c2f934..8b9e44f81 100644 --- a/src/easylogging++.h +++ b/src/easylogging++.h @@ -2538,7 +2538,7 @@ class IWorker { }; #endif // ELPP_ASYNC_LOGGING /// @brief Easylogging++ management storage -class Storage : base::NoCopy { +class Storage : base::NoCopy, public base::threading::ThreadSafe { public: #if ELPP_ASYNC_LOGGING Storage(const LogBuilderPtr& defaultLogBuilder, base::IWorker* asyncDispatchWorker);