Skip to content

Commit 1fa52c3

Browse files
[3.14] gh-148393: Use acquire load for _ma_watcher_tag in dict notify event (gh-148509) (#148512)
The watcher-bits read in _PyDict_NotifyEvent needs to use acquire to synchronize with the release from PyDict_Watch so that the callback publication is visible before the callback is invoked. (cherry picked from commit 19f96f9) Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent e74e59d commit 1fa52c3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ _PyDict_NotifyEvent(PyInterpreterState *interp,
286286
PyObject *value)
287287
{
288288
assert(Py_REFCNT((PyObject*)mp) > 0);
289-
int watcher_bits = FT_ATOMIC_LOAD_UINT64_RELAXED(mp->_ma_watcher_tag) & DICT_WATCHER_MASK;
289+
int watcher_bits = FT_ATOMIC_LOAD_UINT64_ACQUIRE(mp->_ma_watcher_tag) & DICT_WATCHER_MASK;
290290
if (watcher_bits) {
291291
RARE_EVENT_STAT_INC(watched_dict_modification);
292292
_PyDict_SendEvent(watcher_bits, event, mp, key, value);

Include/internal/pycore_pyatomic_ft_wrappers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ extern "C" {
4747
_Py_atomic_load_uint16_relaxed(&value)
4848
#define FT_ATOMIC_LOAD_UINT32_RELAXED(value) \
4949
_Py_atomic_load_uint32_relaxed(&value)
50+
#define FT_ATOMIC_LOAD_UINT64_ACQUIRE(value) \
51+
_Py_atomic_load_uint64_acquire(&value)
5052
#define FT_ATOMIC_LOAD_UINT64_RELAXED(value) \
5153
_Py_atomic_load_uint64_relaxed(&value)
5254
#define FT_ATOMIC_LOAD_ULONG_RELAXED(value) \
@@ -147,6 +149,7 @@ extern "C" {
147149
#define FT_ATOMIC_LOAD_UINT8_RELAXED(value) value
148150
#define FT_ATOMIC_LOAD_UINT16_RELAXED(value) value
149151
#define FT_ATOMIC_LOAD_UINT32_RELAXED(value) value
152+
#define FT_ATOMIC_LOAD_UINT64_ACQUIRE(value) value
150153
#define FT_ATOMIC_LOAD_UINT64_RELAXED(value) value
151154
#define FT_ATOMIC_LOAD_ULONG_RELAXED(value) value
152155
#define FT_ATOMIC_STORE_PTR_RELAXED(value, new_value) value = new_value

0 commit comments

Comments
 (0)