diff options
author | Andres Freund <andres@anarazel.de> | 2018-04-06 20:02:12 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-04-06 20:02:12 -0700 |
commit | 73709f1c1e5860dd9a51ded72634391e9bb73794 (patch) | |
tree | a76764758ebad2f1b367c9393585ad7b92e0e706 /src/include | |
parent | ec349b112366937f87f921bdb80a253e681b211d (diff) | |
download | postgresql-73709f1c1e5860dd9a51ded72634391e9bb73794.tar.gz postgresql-73709f1c1e5860dd9a51ded72634391e9bb73794.zip |
Fix and improve pg_atomic_flag fallback implementation.
The atomics fallback implementation for pg_atomic_flag was broken,
returning the inverted value from pg_atomic_test_set_flag(). This was
unnoticed because a) atomic flags were unused until recently b) the
test code wasn't run when the fallback implementation was in
use (because it didn't allow to test for some edge cases).
Fix the bug, and improve the fallback so it has the same behaviour as
the non-fallback implementation in the problematic edge cases. That
breaks ABI compatibility in the back branches when fallbacks are in
use, but given they were broken until now...
Author: Andres Freund
Reported-by: Daniel Gustafsson
Discussion:
https://postgr.es/m/FB948276-7B32-4B77-83E6-D00167F8EEB4@yesql.se
https://postgr.es/m/20180406233854.uni2h3mbnveczl32@alap3.anarazel.de
Backpatch: 9.5-, where the atomics abstraction was introduced.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/port/atomics/fallback.h | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/src/include/port/atomics/fallback.h b/src/include/port/atomics/fallback.h index a1380034ba9..95b6a652902 100644 --- a/src/include/port/atomics/fallback.h +++ b/src/include/port/atomics/fallback.h @@ -80,6 +80,7 @@ typedef struct pg_atomic_flag #else int sema; #endif + volatile bool value; } pg_atomic_flag; #endif /* PG_HAVE_ATOMIC_FLAG_SUPPORT */ @@ -116,17 +117,7 @@ extern bool pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr); extern void pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr); #define PG_HAVE_ATOMIC_UNLOCKED_TEST_FLAG -static inline bool -pg_atomic_unlocked_test_flag_impl(volatile pg_atomic_flag *ptr) -{ - /* - * Can't do this efficiently in the semaphore based implementation - we'd - * have to try to acquire the semaphore - so always return true. That's - * correct, because this is only an unlocked test anyway. Do this in the - * header so compilers can optimize the test away. - */ - return true; -} +extern bool pg_atomic_unlocked_test_flag_impl(volatile pg_atomic_flag *ptr); #endif /* PG_HAVE_ATOMIC_FLAG_SIMULATION */ |