diff options
author | Tor Egge <Tor.Egge@oath.com> | 2017-10-27 20:42:27 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-10-27 20:42:27 +0000 |
commit | 7e0ce424c29f5ee4a89c5c4a989fe2538cc9078d (patch) | |
tree | 480e467c684d1b6d9639d40ec589c73c0367e5f4 /vespalog/src | |
parent | 86730de554af723ffd5e4d57b7e3e4d54cb61c0f (diff) |
Use std::mutex instead of FastOS_Mutex in slobrok and vespalog modules.
Diffstat (limited to 'vespalog/src')
-rw-r--r-- | vespalog/src/vespa/log/bufferedlogger.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/vespalog/src/vespa/log/bufferedlogger.cpp b/vespalog/src/vespa/log/bufferedlogger.cpp index 106a9bc1dba..5c243b86f86 100644 --- a/vespalog/src/vespa/log/bufferedlogger.cpp +++ b/vespalog/src/vespa/log/bufferedlogger.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bufferedlogger.h" -#include <vespa/fastos/mutex.h> #include <boost/multi_index_container.hpp> #include <boost/multi_index/identity.hpp> #include <boost/multi_index/member.hpp> @@ -13,6 +12,7 @@ #include <sstream> #include <vector> #include <cstdarg> +#include <mutex> namespace ns_log { @@ -23,7 +23,7 @@ class BackingBuffer { public: std::unique_ptr<Timer> _timer; /** Lock needed to access cache. */ - mutable FastOS_Mutex _mutex; + mutable std::mutex _mutex; static uint64_t _countFactor; @@ -100,9 +100,8 @@ public: * need to empty buffer before new log messages arive. */ void trimCache() { - _mutex.Lock(); + std::lock_guard<std::mutex> guard(_mutex); trimCache(_timer->getTimestamp()); - _mutex.Unlock(); } /** @@ -240,7 +239,7 @@ BackingBuffer::logImpl(Logger& l, Logger::LogLevel level, { Entry entry(level, file, line, token, message, _timer->getTimestamp(), l); - _mutex.Lock(); + std::lock_guard<std::mutex> guard(_mutex); LogCacheFrontToken::iterator it1 = _cacheFront.get<1>().find(entry); LogCacheBackToken::iterator it2 = _cacheBack.get<1>().find(entry); if (it1 != _cacheFront.get<1>().end()) { @@ -257,13 +256,12 @@ BackingBuffer::logImpl(Logger& l, Logger::LogLevel level, _cacheFront.push_back(entry); } trimCache(entry._timestamp); - _mutex.Unlock(); } void BackingBuffer::flush() { - _mutex.Lock(); + std::lock_guard<std::mutex> guard(_mutex); for (LogCacheBack::const_iterator it = _cacheBack.begin(); it != _cacheBack.end(); ++it) { @@ -276,7 +274,6 @@ BackingBuffer::flush() log(*it); } _cacheFront.clear(); - _mutex.Unlock(); } void @@ -340,7 +337,7 @@ BackingBuffer::toString() const { std::ostringstream ost; ost << "Front log cache content:\n"; - _mutex.Lock(); + std::lock_guard<std::mutex> guard(_mutex); for (LogCacheFront::const_iterator it = _cacheFront.begin(); it != _cacheFront.end(); ++it) { @@ -352,7 +349,6 @@ BackingBuffer::toString() const { ost << " " << it->toString() << "\n"; } - _mutex.Unlock(); return ost.str(); } |