]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112075: Dictionary global version counter should use atomic increments (#114568)
authorDino Viehland <dinoviehland@meta.com>
Mon, 29 Jan 2024 17:47:54 +0000 (09:47 -0800)
committerGitHub <noreply@github.com>
Mon, 29 Jan 2024 17:47:54 +0000 (09:47 -0800)
Dictionary global version counter should use atomic increments

Include/internal/pycore_dict.h

index d96870e9197bbf0d8000da7eae5a4bb2efee20b0..b4e1f8cf1e320b3c10f26ad8d846cb59a78beb41 100644 (file)
@@ -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,