mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 23:27:21 +01:00
Merge #9230: Fix some benign races in timestamp logging
8b22efb
Make fStartedNewLine an std::atomic_bool (Matt Corallo)507145d
Fix race when accessing std::locale::classic() (Matt Corallo)
This commit is contained in:
commit
c79e52ad30
2 changed files with 4 additions and 3 deletions
|
@ -258,7 +258,7 @@ bool LogAcceptCategory(const char* category)
|
||||||
* suppress printing of the timestamp when multiple calls are made that don't
|
* suppress printing of the timestamp when multiple calls are made that don't
|
||||||
* end in a newline. Initialize it to true, and hold it, in the calling context.
|
* end in a newline. Initialize it to true, and hold it, in the calling context.
|
||||||
*/
|
*/
|
||||||
static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine)
|
static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine)
|
||||||
{
|
{
|
||||||
string strStamped;
|
string strStamped;
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine
|
||||||
int LogPrintStr(const std::string &str)
|
int LogPrintStr(const std::string &str)
|
||||||
{
|
{
|
||||||
int ret = 0; // Returns total number of characters written
|
int ret = 0; // Returns total number of characters written
|
||||||
static bool fStartedNewLine = true;
|
static std::atomic_bool fStartedNewLine(true);
|
||||||
|
|
||||||
string strTimestamped = LogTimestampStr(str, &fStartedNewLine);
|
string strTimestamped = LogTimestampStr(str, &fStartedNewLine);
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,9 @@ void MilliSleep(int64_t n)
|
||||||
|
|
||||||
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
|
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
|
||||||
{
|
{
|
||||||
|
static std::locale classic(std::locale::classic());
|
||||||
// std::locale takes ownership of the pointer
|
// std::locale takes ownership of the pointer
|
||||||
std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
|
std::locale loc(classic, new boost::posix_time::time_facet(pszFormat));
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss.imbue(loc);
|
ss.imbue(loc);
|
||||||
ss << boost::posix_time::from_time_t(nTime);
|
ss << boost::posix_time::from_time_t(nTime);
|
||||||
|
|
Loading…
Add table
Reference in a new issue