summaryrefslogtreecommitdiffstats
path: root/Python/lock.c
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-04-17 17:19:28 (GMT)
committerGitHub <noreply@github.com>2024-04-17 17:19:28 (GMT)
commit0d29302155f49d4d5c7fa34a658ad5a97dd013a2 (patch)
tree84ab95a6fa91eb9c4c600fd452e9b6495529bb39 /Python/lock.c
parentb6c62c79e7d9592ca1ea6b93f6ce3dd3829939d0 (diff)
downloadcpython-0d29302155f49d4d5c7fa34a658ad5a97dd013a2.zip
cpython-0d29302155f49d4d5c7fa34a658ad5a97dd013a2.tar.gz
cpython-0d29302155f49d4d5c7fa34a658ad5a97dd013a2.tar.bz2
gh-117657: Quiet erroneous TSAN reports of data races in `_PySeqLock` (#117955)
Quiet erroneous TSAN reports of data races in `_PySeqLock` TSAN reports a couple of data races between the compare/exchange in `_PySeqLock_LockWrite` and the non-atomic loads in `_PySeqLock_{Abandon,Unlock}Write`. This is another instance of TSAN incorrectly modeling failed compare/exchange as a write instead of a load.
Diffstat (limited to 'Python/lock.c')
-rw-r--r--Python/lock.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Python/lock.c b/Python/lock.c
index 7d1ead5..91c66df 100644
--- a/Python/lock.c
+++ b/Python/lock.c
@@ -472,7 +472,7 @@ _PyRWMutex_Unlock(_PyRWMutex *rwmutex)
void _PySeqLock_LockWrite(_PySeqLock *seqlock)
{
- // lock the entry by setting by moving to an odd sequence number
+ // lock by moving to an odd sequence number
uint32_t prev = _Py_atomic_load_uint32_relaxed(&seqlock->sequence);
while (1) {
if (SEQLOCK_IS_UPDATING(prev)) {
@@ -492,14 +492,14 @@ void _PySeqLock_LockWrite(_PySeqLock *seqlock)
void _PySeqLock_AbandonWrite(_PySeqLock *seqlock)
{
- uint32_t new_seq = seqlock->sequence - 1;
+ uint32_t new_seq = _Py_atomic_load_uint32_relaxed(&seqlock->sequence) - 1;
assert(!SEQLOCK_IS_UPDATING(new_seq));
_Py_atomic_store_uint32(&seqlock->sequence, new_seq);
}
void _PySeqLock_UnlockWrite(_PySeqLock *seqlock)
{
- uint32_t new_seq = seqlock->sequence + 1;
+ uint32_t new_seq = _Py_atomic_load_uint32_relaxed(&seqlock->sequence) + 1;
assert(!SEQLOCK_IS_UPDATING(new_seq));
_Py_atomic_store_uint32(&seqlock->sequence, new_seq);
}