refactor: Rename LockGuard to StdLockGuard for consistency with StdMutex

This commit is contained in:
Hennadii Stepanov 2020-05-28 09:42:26 +03:00
parent 79be487420
commit dfb75ae49d
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
3 changed files with 11 additions and 11 deletions

View file

@ -41,7 +41,7 @@ static int FileWriteStr(const std::string &str, FILE *fp)
bool BCLog::Logger::StartLogging() bool BCLog::Logger::StartLogging()
{ {
LockGuard scoped_lock(m_cs); StdLockGuard scoped_lock(m_cs);
assert(m_buffering); assert(m_buffering);
assert(m_fileout == nullptr); assert(m_fileout == nullptr);
@ -80,7 +80,7 @@ bool BCLog::Logger::StartLogging()
void BCLog::Logger::DisconnectTestLogger() void BCLog::Logger::DisconnectTestLogger()
{ {
LockGuard scoped_lock(m_cs); StdLockGuard scoped_lock(m_cs);
m_buffering = true; m_buffering = true;
if (m_fileout != nullptr) fclose(m_fileout); if (m_fileout != nullptr) fclose(m_fileout);
m_fileout = nullptr; m_fileout = nullptr;
@ -246,7 +246,7 @@ namespace BCLog {
void BCLog::Logger::LogPrintStr(const std::string& str) void BCLog::Logger::LogPrintStr(const std::string& str)
{ {
LockGuard scoped_lock(m_cs); StdLockGuard scoped_lock(m_cs);
std::string str_prefixed = LogEscapeMessage(str); std::string str_prefixed = LogEscapeMessage(str);
if (m_log_threadnames && m_started_new_line) { if (m_log_threadnames && m_started_new_line) {

View file

@ -100,14 +100,14 @@ namespace BCLog {
/** Returns whether logs will be written to any output */ /** Returns whether logs will be written to any output */
bool Enabled() const bool Enabled() const
{ {
LockGuard scoped_lock(m_cs); StdLockGuard scoped_lock(m_cs);
return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty(); return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty();
} }
/** Connect a slot to the print signal and return the connection */ /** Connect a slot to the print signal and return the connection */
std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun) std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun)
{ {
LockGuard scoped_lock(m_cs); StdLockGuard scoped_lock(m_cs);
m_print_callbacks.push_back(std::move(fun)); m_print_callbacks.push_back(std::move(fun));
return --m_print_callbacks.end(); return --m_print_callbacks.end();
} }
@ -115,7 +115,7 @@ namespace BCLog {
/** Delete a connection */ /** Delete a connection */
void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it) void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it)
{ {
LockGuard scoped_lock(m_cs); StdLockGuard scoped_lock(m_cs);
m_print_callbacks.erase(it); m_print_callbacks.erase(it);
} }

View file

@ -62,13 +62,13 @@ class LOCKABLE StdMutex : public std::mutex
{ {
}; };
// LockGuard provides an annotated version of lock_guard for us // StdLockGuard provides an annotated version of std::lock_guard for us,
// should only be used when sync.h Mutex/LOCK/etc aren't usable // and should only be used when sync.h Mutex/LOCK/etc are not usable.
class SCOPED_LOCKABLE LockGuard : public std::lock_guard<StdMutex> class SCOPED_LOCKABLE StdLockGuard : public std::lock_guard<StdMutex>
{ {
public: public:
explicit LockGuard(StdMutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard<StdMutex>(cs) {} explicit StdLockGuard(StdMutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard<StdMutex>(cs) {}
~LockGuard() UNLOCK_FUNCTION() {}; ~StdLockGuard() UNLOCK_FUNCTION() {}
}; };
#endif // BITCOIN_THREADSAFETY_H #endif // BITCOIN_THREADSAFETY_H