Skip to content

Commit 19f96f9

Browse files
authored
gh-148393: Use acquire load for _ma_watcher_tag in dict notify event (gh-148509)
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.
1 parent e689394 commit 19f96f9

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
@@ -292,7 +292,7 @@ _PyDict_NotifyEvent(PyDict_WatchEvent event,
292292
PyObject *value)
293293
{
294294
assert(Py_REFCNT((PyObject*)mp) > 0);
295-
int watcher_bits = FT_ATOMIC_LOAD_UINT64_RELAXED(mp->_ma_watcher_tag) & DICT_WATCHER_MASK;
295+
int watcher_bits = FT_ATOMIC_LOAD_UINT64_ACQUIRE(mp->_ma_watcher_tag) & DICT_WATCHER_MASK;
296296
if (watcher_bits) {
297297
RARE_EVENT_STAT_INC(watched_dict_modification);
298298
_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
@@ -49,6 +49,8 @@ extern "C" {
4949
_Py_atomic_load_uint16_relaxed(&value)
5050
#define FT_ATOMIC_LOAD_UINT32_RELAXED(value) \
5151
_Py_atomic_load_uint32_relaxed(&value)
52+
#define FT_ATOMIC_LOAD_UINT64_ACQUIRE(value) \
53+
_Py_atomic_load_uint64_acquire(&value)
5254
#define FT_ATOMIC_LOAD_UINT64_RELAXED(value) \
5355
_Py_atomic_load_uint64_relaxed(&value)
5456
#define FT_ATOMIC_LOAD_ULONG_RELAXED(value) \
@@ -154,6 +156,7 @@ extern "C" {
154156
#define FT_ATOMIC_LOAD_UINT8_RELAXED(value) value
155157
#define FT_ATOMIC_LOAD_UINT16_RELAXED(value) value
156158
#define FT_ATOMIC_LOAD_UINT32_RELAXED(value) value
159+
#define FT_ATOMIC_LOAD_UINT64_ACQUIRE(value) value
157160
#define FT_ATOMIC_LOAD_UINT64_RELAXED(value) value
158161
#define FT_ATOMIC_LOAD_ULONG_RELAXED(value) value
159162
#define FT_ATOMIC_STORE_PTR_RELAXED(value, new_value) value = new_value

0 commit comments

Comments
 (0)