diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/util.cpp b/src/util.cpp index 18a020ccd9..dbf9065113 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4,7 +4,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <util.h> -#include <fs.h> #include <chainparamsbase.h> #include <random.h> @@ -79,6 +78,7 @@ #include <openssl/crypto.h> #include <openssl/rand.h> #include <openssl/conf.h> +#include <thread> // Application startup time (used for uptime calculation) const int64_t nStartupTime = GetTime(); @@ -159,10 +159,10 @@ instance_of_cinit; * the mutex). */ -static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT; +static std::once_flag debugPrintInitFlag; /** - * We use boost::call_once() to make sure mutexDebugLog and + * We use std::call_once() to make sure mutexDebugLog and * vMsgsBeforeOpenLog are initialized in a thread-safe manner. * * NOTE: fileout, mutexDebugLog and sometimes vMsgsBeforeOpenLog @@ -171,7 +171,7 @@ static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT; * tested, explicit destruction of these objects can be implemented. */ static FILE* fileout = nullptr; -static boost::mutex* mutexDebugLog = nullptr; +static std::mutex* mutexDebugLog = nullptr; static std::list<std::string>* vMsgsBeforeOpenLog; static int FileWriteStr(const std::string &str, FILE *fp) @@ -182,7 +182,7 @@ static int FileWriteStr(const std::string &str, FILE *fp) static void DebugPrintInit() { assert(mutexDebugLog == nullptr); - mutexDebugLog = new boost::mutex(); + mutexDebugLog = new std::mutex(); vMsgsBeforeOpenLog = new std::list<std::string>; } @@ -194,8 +194,8 @@ fs::path GetDebugLogPath() bool OpenDebugLog() { - boost::call_once(&DebugPrintInit, debugPrintInitFlag); - boost::mutex::scoped_lock scoped_lock(*mutexDebugLog); + std::call_once(debugPrintInitFlag, &DebugPrintInit); + std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog); assert(fileout == nullptr); assert(vMsgsBeforeOpenLog); @@ -314,12 +314,14 @@ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fSt if (*fStartedNewLine) { int64_t nTimeMicros = GetTimeMicros(); - strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000); - if (fLogTimeMicros) - strStamped += strprintf(".%06d", nTimeMicros%1000000); + strStamped = FormatISO8601DateTime(nTimeMicros/1000000); + if (fLogTimeMicros) { + strStamped.pop_back(); + strStamped += strprintf(".%06dZ", nTimeMicros%1000000); + } int64_t mocktime = GetMockTime(); if (mocktime) { - strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")"; + strStamped += " (mocktime: " + FormatISO8601DateTime(mocktime) + ")"; } strStamped += ' ' + str; } else @@ -348,8 +350,8 @@ int LogPrintStr(const std::string &str) } else if (fPrintToDebugLog) { - boost::call_once(&DebugPrintInit, debugPrintInitFlag); - boost::mutex::scoped_lock scoped_lock(*mutexDebugLog); + std::call_once(debugPrintInitFlag, &DebugPrintInit); + std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog); // buffer if we haven't opened the log yet if (fileout == nullptr) { @@ -417,6 +419,19 @@ void ReleaseDirectoryLocks() dir_locks.clear(); } +bool DirIsWritable(const fs::path& directory) +{ + fs::path tmpFile = directory / fs::unique_path(); + + FILE* file = fsbridge::fopen(tmpFile, "a"); + if (!file) return false; + + fclose(file); + remove(tmpFile); + + return true; +} + /** Interpret string as boolean, for argument parsing */ static bool InterpretBool(const std::string& strValue) { @@ -960,11 +975,7 @@ bool SetupNetworking() int GetNumCores() { -#if BOOST_VERSION >= 105600 - return boost::thread::physical_concurrency(); -#else // Must fall back to hardware_concurrency, which unfortunately counts virtual cores - return boost::thread::hardware_concurrency(); -#endif + return std::thread::hardware_concurrency(); } std::string CopyrightHolders(const std::string& strPrefix) |