summaryrefslogtreecommitdiff
path: root/absl/debugging
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-10-13 08:26:15 -0700
committerGravatar Derek Mauro <dmauro@google.com>2020-10-13 12:49:13 -0400
commitf3f785ab59478dd0312bf1b5df65d380650bf0dc (patch)
treec6cb0ba6e13b43ccfc1c60bf4dfed9ea0d38e62f /absl/debugging
parent4b2fbb4adba905eede6c61b4494acfdb660a3bb7 (diff)
Export of internal Abseil changes
-- 5bd06440e700fefd6eadd577d7d69c51f15c63e0 by Abseil Team <absl-team@google.com>: Add if-guard to futex.h so that it doesn't fail to parse for unsupported platforms PiperOrigin-RevId: 336880375 -- 8b3d3bb4ad123fc9f648f0e397b2eddd88dc0c02 by Derek Mauro <dmauro@google.com>: Fix race in AddressIsReadable file descriptors using stronger memory ordering PiperOrigin-RevId: 336874423 -- 1d8bf23747009cca29129b80c2793bc91443dd55 by Derek Mauro <dmauro@google.com>: Avoid -Wundef warnings on ABSL_HAVE_THREAD_LOCAL PiperOrigin-RevId: 336792406 -- 562a480f029c600c1d3b1428da6a9b09e8952a74 by Derek Mauro <dmauro@google.com>: Fix preprocessor condition for symbols __tsan_mutex_read_lock and __tsan_mutex_try_lock PiperOrigin-RevId: 336732571 GitOrigin-RevId: 5bd06440e700fefd6eadd577d7d69c51f15c63e0 Change-Id: Id9bb331baec74b9d80c7b228959a7739bc30e694
Diffstat (limited to 'absl/debugging')
-rw-r--r--absl/debugging/internal/address_is_readable.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/absl/debugging/internal/address_is_readable.cc b/absl/debugging/internal/address_is_readable.cc
index 65376063..329c285f 100644
--- a/absl/debugging/internal/address_is_readable.cc
+++ b/absl/debugging/internal/address_is_readable.cc
@@ -68,6 +68,7 @@ static void Unpack(uint64_t x, int *pid, int *read_fd, int *write_fd) {
// unimplemented.
// This is a namespace-scoped variable for correct zero-initialization.
static std::atomic<uint64_t> pid_and_fds; // initially 0, an invalid pid.
+
bool AddressIsReadable(const void *addr) {
absl::base_internal::ErrnoSaver errno_saver;
// We test whether a byte is readable by using write(). Normally, this would
@@ -86,7 +87,7 @@ bool AddressIsReadable(const void *addr) {
int pid;
int read_fd;
int write_fd;
- uint64_t local_pid_and_fds = pid_and_fds.load(std::memory_order_relaxed);
+ uint64_t local_pid_and_fds = pid_and_fds.load(std::memory_order_acquire);
Unpack(local_pid_and_fds, &pid, &read_fd, &write_fd);
while (current_pid != pid) {
int p[2];
@@ -98,13 +99,13 @@ bool AddressIsReadable(const void *addr) {
fcntl(p[1], F_SETFD, FD_CLOEXEC);
uint64_t new_pid_and_fds = Pack(current_pid, p[0], p[1]);
if (pid_and_fds.compare_exchange_strong(
- local_pid_and_fds, new_pid_and_fds, std::memory_order_relaxed,
+ local_pid_and_fds, new_pid_and_fds, std::memory_order_release,
std::memory_order_relaxed)) {
local_pid_and_fds = new_pid_and_fds; // fds exposed to other threads
} else { // fds not exposed to other threads; we can close them.
close(p[0]);
close(p[1]);
- local_pid_and_fds = pid_and_fds.load(std::memory_order_relaxed);
+ local_pid_and_fds = pid_and_fds.load(std::memory_order_acquire);
}
Unpack(local_pid_and_fds, &pid, &read_fd, &write_fd);
}
@@ -124,7 +125,7 @@ bool AddressIsReadable(const void *addr) {
// If pid_and_fds contains the problematic file descriptors we just used,
// this call will forget them, and the loop will try again.
pid_and_fds.compare_exchange_strong(local_pid_and_fds, 0,
- std::memory_order_relaxed,
+ std::memory_order_release,
std::memory_order_relaxed);
}
} while (errno == EBADF);