8000 gh-112075: Dictionary global version counter should use atomic increm… · python/cpython@0cd9bac · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cd9bac

Browse files
authored
gh-112075: Dictionary global version counter should use atomic increments (#114568)
Dictionary global version counter should use atomic increments
1 parent 3d71665 commit 0cd9bac

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Include/internal/pycore_dict.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,14 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
209209
#define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS)
210210
#define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1)
211211

212+
#ifdef Py_GIL_DISABLED
213+
#define DICT_NEXT_VERSION(INTERP) \
214+
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
215+
216+
#else
212217
#define DICT_NEXT_VERSION(INTERP) \
213218
((INTERP)->dict_state.global_version += DICT_VERSION_INCREMENT)
219+
#endif
214220

215221
void
216222
_PyDict_SendEvent(int watcher_bits,

0 commit comments

Comments
 (0)
0