diff options
author | Dino Viehland <dinoviehland@meta.com> | 2024-01-29 17:47:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-29 17:47:54 (GMT) |
commit | 0cd9bacb8ad41fe86f95b326e9199caa749539eb (patch) | |
tree | 4d36e8ba70a3a122e7af6723dfd199379df0e007 /Include | |
parent | 3d716655d22dc14e79ac0d30f33eef0a49efdac0 (diff) | |
download | cpython-0cd9bacb8ad41fe86f95b326e9199caa749539eb.zip cpython-0cd9bacb8ad41fe86f95b326e9199caa749539eb.tar.gz cpython-0cd9bacb8ad41fe86f95b326e9199caa749539eb.tar.bz2 |
gh-112075: Dictionary global version counter should use atomic increments (#114568)
Dictionary global version counter should use atomic increments
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_dict.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h index d96870e..b4e1f8c 100644 --- a/Include/internal/pycore_dict.h +++ b/Include/internal/pycore_dict.h @@ -209,8 +209,14 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) { #define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS) #define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1) +#ifdef Py_GIL_DISABLED +#define DICT_NEXT_VERSION(INTERP) \ + (_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT) + +#else #define DICT_NEXT_VERSION(INTERP) \ ((INTERP)->dict_state.global_version += DICT_VERSION_INCREMENT) +#endif void _PyDict_SendEvent(int watcher_bits, |