I noticed that the fallback pg_atomic_test_set_flag_impl() implementation
that uses atomic-exchange is giving pg_atomic_exchange_u32_impl() an extra
argument.  This appears to be copy/pasted from the atomic-compare-exchange
version a few lines down.  It looks like it's been this way since this code
was introduced in commit b64d92f (2014).  Patch attached.

I'd ordinarily suggest removing this section of code since it doesn't seem
to have gotten much coverage, but I'm actually looking into adding some
faster atomic-exchange implementations that may activate this code for
certain compiler/architecture combinations.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
diff --git a/src/include/port/atomics/generic.h b/src/include/port/atomics/generic.h
index cb5804adbf..95d99dd0be 100644
--- a/src/include/port/atomics/generic.h
+++ b/src/include/port/atomics/generic.h
@@ -83,7 +83,7 @@ pg_atomic_init_flag_impl(volatile pg_atomic_flag *ptr)
 static inline bool
 pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr)
 {
-	return pg_atomic_exchange_u32_impl(ptr, &value, 1) == 0;
+	return pg_atomic_exchange_u32_impl(ptr, 1) == 0;
 }
 
 #define PG_HAVE_ATOMIC_UNLOCKED_TEST_FLAG

Reply via email to