Skip to content

Commit b1e0a7c

Browse files
committed
Improved performance by not locking when message is discarded
1 parent dac66b6 commit b1e0a7c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

.travis.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ matrix:
1313
- COMPILER=clang++
1414
- CPPFLAGS="-I /usr/include/c++/v1"
1515
- CPPFLAGS="-stdlib=libc++"
16-
- os: osx
17-
compiler: clang
18-
env:
19-
- COMPILER=clang++
20-
- CPPFLAGS="-stdlib=libc++"
21-
# GCC is linked to clang, so we don't need to compile twice for same compiler/platform
16+
# - os: osx
17+
# compiler: clang
18+
# env:
19+
# - COMPILER=clang++
20+
# - CPPFLAGS="-stdlib=libc++"
21+
# # GCC is linked to clang, so we don't need to compile twice for same compiler/platform
2222

2323
before_script:
2424
- echo $TRAVIS_OS_NAME

src/logger.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ void ConsoleLogger::logMessage(const Level level,
6767
const std::wstring& local,
6868
const std::chrono::system_clock::time_point timestamp)
6969
{
70+
if (!logLevel(level)) {
71+
return;
72+
}
7073
std::lock_guard<std::mutex> guard(writeLock);
71-
if (!logLevel(level)) {
72-
return;
73-
}
7474
if (level == Level::ERROR || level == Level::SEVERE) {
7575
std::wcerr << toString(level) << " " << getCurrentTime() << ": " << local;
7676
}
@@ -93,10 +93,10 @@ void FileLogger::logMessage(const Level level,
9393
const std::wstring& local,
9494
const std::chrono::system_clock::time_point timestamp)
9595
{
96-
std::lock_guard<std::mutex> guard(writeLock);
9796
if (!logLevel(level)) {
9897
return;
9998
}
99+
std::lock_guard<std::mutex> guard(writeLock);
100100
fileStream << toString(level) << " " << getCurrentTime() << ": " << local;
101101
}
102102

@@ -112,10 +112,10 @@ void ColoredLogger::logMessage(const Level level,
112112
const std::wstring& local,
113113
const std::chrono::system_clock::time_point timestamp)
114114
{
115-
std::lock_guard<std::mutex> guard(writeLock);
116115
if (!logLevel(level)) {
117116
return;
118117
}
118+
std::lock_guard<std::mutex> guard(writeLock);
119119
if (level == Level::ERROR || level == Level::SEVERE) {
120120
stream << "\033[31m" << toString(level) << " " << getCurrentTime() << ": " << local << "\033[39;49m";
121121

0 commit comments

Comments
 (0)