From 42d509b1c3cff5de076607229f0a92e81f72b9d6 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Wed, 22 Dec 2021 14:47:32 +0100 Subject: [PATCH] revert to int atomics --- src/glog/logging.h.in | 29 ++++++++++++++--------------- src/logging.cc | 7 +++---- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 3b32758..2efb672 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -1101,7 +1101,7 @@ namespace google { #if @ac_cv_cxx11_atomic@ && __cplusplus >= 201103L #define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \ - static std::atomic LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \ + static std::atomic LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \ ++LOG_OCCURRENCES; \ @@ -1112,7 +1112,7 @@ namespace google { &what_to_do).stream() #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ - static std::atomic LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \ + static std::atomic LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \ ++LOG_OCCURRENCES; \ @@ -1123,7 +1123,7 @@ namespace google { &what_to_do).stream() #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ - static std::atomic LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \ + static std::atomic LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \ ++LOG_OCCURRENCES; \ @@ -1134,7 +1134,7 @@ namespace google { &what_to_do).stream() #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ - static std::atomic LOG_OCCURRENCES(0); \ + static std::atomic LOG_OCCURRENCES(0); \ GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \ if (LOG_OCCURRENCES <= n) \ ++LOG_OCCURRENCES; \ @@ -1191,7 +1191,7 @@ namespace google { #else #define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \ - static unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ + static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ __sync_add_and_fetch(&LOG_OCCURRENCES, 1); \ if (__sync_add_and_fetch(&LOG_OCCURRENCES_MOD_N, 1) > n) \ __sync_sub_and_fetch(&LOG_OCCURRENCES_MOD_N, n); \ @@ -1201,7 +1201,7 @@ namespace google { &what_to_do).stream() #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ - static unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ + static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ __sync_add_and_fetch(&LOG_OCCURRENCES, 1); \ if ((condition) && \ (__sync_add_and_fetch(&LOG_OCCURRENCES_MOD_N, 1) || true) && \ @@ -1212,7 +1212,7 @@ namespace google { &what_to_do).stream() #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ - static unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ + static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ __sync_add_and_fetch(&LOG_OCCURRENCES, 1); \ if (__sync_add_and_fetch(&LOG_OCCURRENCES_MOD_N, 1) > n) \ __sync_sub_and_fetch(&LOG_OCCURRENCES_MOD_N, n); \ @@ -1222,7 +1222,7 @@ namespace google { &what_to_do).stream() #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ - static unsigned LOG_OCCURRENCES = 0; \ + static int LOG_OCCURRENCES = 0; \ if (LOG_OCCURRENCES <= n) \ __sync_add_and_fetch(&LOG_OCCURRENCES, 1); \ if (LOG_OCCURRENCES <= n) \ @@ -1466,7 +1466,7 @@ GLOG_MSVC_PUSH_DISABLE_WARNING(4275) class GOOGLE_GLOG_DLL_DECL LogStream : public std::ostream { GLOG_MSVC_POP_WARNING() public: - LogStream(char *buf, int len, uint64 ctr) + LogStream(char *buf, int len, int64 ctr) : std::ostream(NULL), streambuf_(buf, len), ctr_(ctr), @@ -1474,8 +1474,8 @@ GLOG_MSVC_POP_WARNING() rdbuf(&streambuf_); } - uint64 ctr() const { return ctr_; } - void set_ctr(uint64 ctr) { ctr_ = ctr; } + int64 ctr() const { return ctr_; } + void set_ctr(int64 ctr) { ctr_ = ctr; } LogStream* self() const { return self_; } // Legacy std::streambuf methods. @@ -1487,7 +1487,7 @@ GLOG_MSVC_POP_WARNING() LogStream(const LogStream&); LogStream& operator=(const LogStream&); base_logging::LogStreamBuf streambuf_; - uint64 ctr_; // Counter hack (for the LOG_EVERY_X() macro) + int64 ctr_; // Counter hack (for the LOG_EVERY_X() macro) LogStream *self_; // Consistency check hack }; @@ -1495,7 +1495,7 @@ public: // icc 8 requires this typedef to avoid an internal compiler error. typedef void (LogMessage::*SendMethod)(); - LogMessage(const char* file, int line, LogSeverity severity, uint64 ctr, + LogMessage(const char* file, int line, LogSeverity severity, int64 ctr, SendMethod send_method); // Two special constructors that generate reduced amounts of code at @@ -1668,8 +1668,7 @@ GOOGLE_GLOG_DLL_DECL std::ostream& operator<<(std::ostream &os, // Derived class for PLOG*() above. class GOOGLE_GLOG_DLL_DECL ErrnoLogMessage : public LogMessage { public: - - ErrnoLogMessage(const char* file, int line, LogSeverity severity, uint64 ctr, + ErrnoLogMessage(const char* file, int line, LogSeverity severity, int64 ctr, void (LogMessage::*send_method)()); // Postpends ": strerror(errno) [errno]". diff --git a/src/logging.cc b/src/logging.cc index e97a01b..3e281e2 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -1507,7 +1507,7 @@ LogMessage::LogMessageData::LogMessageData() } LogMessage::LogMessage(const char* file, int line, LogSeverity severity, - uint64 ctr, void (LogMessage::*send_method)()) + int64 ctr, void (LogMessage::*send_method)()) : allocated_(NULL) { Init(file, line, severity, send_method); data_->stream_.set_ctr(ctr); @@ -1987,10 +1987,9 @@ ostream& operator<<(ostream &os, const PRIVATE_Counter&) { } ErrnoLogMessage::ErrnoLogMessage(const char* file, int line, - LogSeverity severity, uint64 ctr, + LogSeverity severity, int64 ctr, void (LogMessage::*send_method)()) - : LogMessage(file, line, severity, ctr, send_method) { -} + : LogMessage(file, line, severity, ctr, send_method) {} ErrnoLogMessage::~ErrnoLogMessage() { // Don't access errno directly because it may have been altered