Skip to content

Commit b4a4a6b

Browse files
derekmaurocopybara-github
authored andcommitted
Replace std::atomic_flag with std::atomic<bool> to avoid the C++20
deprecation of ATOMIC_FLAG_INIT. Another option would have been to use macros to only initialize std::atomic_flag before C++20, but I decided to use one compilation path instead. The major difference between std::atomic_flag and std::atomic<bool> is that the former is guaranteed to be lock-free, but we already assume std::atomic<bool> is lock-free in many places. https://en.cppreference.com/w/cpp/atomic/atomic_flag PiperOrigin-RevId: 487397075 Change-Id: I3f1c539ec8b2ca58547282e69ed73e93243e8efe
1 parent db8cd47 commit b4a4a6b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

absl/debugging/internal/stacktrace_x86-inl.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <cstdint>
3030
#include <limits>
3131

32+
#include "absl/base/attributes.h"
3233
#include "absl/base/macros.h"
3334
#include "absl/base/port.h"
3435
#include "absl/debugging/internal/address_is_readable.h"

absl/log/internal/log_message.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,16 @@ void LogMessage::Flush() {
372372
}
373373

374374
// Have we already seen a fatal message?
375-
ABSL_CONST_INIT static std::atomic_flag seen_fatal = ATOMIC_FLAG_INIT;
375+
ABSL_CONST_INIT static std::atomic<bool> seen_fatal(false);
376376
if (data_->entry.log_severity() == absl::LogSeverity::kFatal &&
377377
absl::log_internal::ExitOnDFatal()) {
378378
// Exactly one LOG(FATAL) message is responsible for aborting the process,
379379
// even if multiple threads LOG(FATAL) concurrently.
380-
data_->first_fatal = !seen_fatal.test_and_set(std::memory_order_relaxed);
380+
bool expected_seen_fatal = false;
381+
if (seen_fatal.compare_exchange_strong(expected_seen_fatal, true,
382+
std::memory_order_relaxed)) {
383+
data_->first_fatal = true;
384+
}
381385
}
382386

383387
data_->entry.text_message_with_prefix_and_newline_and_nul_ =

0 commit comments

Comments
 (0)