@@ -41,6 +41,12 @@ get_functools_state(PyObject *module)
4141 return (_functools_state * )state ;
4242}
4343
44+ #ifdef Py_GIL_DISABLED
45+ #define FT_ATOMIC_ADD_SSIZE (value , new_value ) \
46+ _Py_atomic_add_ssize(&value, new_value)
47+ #else
48+ #define FT_ATOMIC_ADD_SSIZE (value , new_value ) value += new_value
49+ #endif
4450
4551/* partial object **********************************************************/
4652
@@ -1176,11 +1182,7 @@ uncached_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd
11761182{
11771183 PyObject * result ;
11781184
1179- #ifdef Py_GIL_DISABLED
1180- _Py_atomic_add_ssize (& self -> misses , 1 );
1181- #else
1182- self -> misses ++ ;
1183- #endif
1185+ FT_ATOMIC_ADD_SSIZE (self -> misses , 1 );
11841186 result = PyObject_Call (self -> func , args , kwds );
11851187 if (!result )
11861188 return NULL ;
@@ -1202,23 +1204,15 @@ infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd
12021204 }
12031205 int res = _PyDict_GetItemRef_KnownHash ((PyDictObject * )self -> cache , key , hash , & result );
12041206 if (res > 0 ) {
1205- #ifdef Py_GIL_DISABLED
1206- _Py_atomic_add_ssize (& self -> hits , 1 );
1207- #else
1208- self -> hits ++ ;
1209- #endif
1207+ FT_ATOMIC_ADD_SSIZE (self -> hits , 1 );
12101208 Py_DECREF (key );
12111209 return result ;
12121210 }
12131211 if (res < 0 ) {
12141212 Py_DECREF (key );
12151213 return NULL ;
12161214 }
1217- #ifdef Py_GIL_DISABLED
1218- _Py_atomic_add_ssize (& self -> misses , 1 );
1219- #else
1220- self -> misses ++ ;
1221- #endif
1215+ FT_ATOMIC_ADD_SSIZE (self -> misses , 1 );
12221216 result = PyObject_Call (self -> func , args , kwds );
12231217 if (!result ) {
12241218 Py_DECREF (key );
0 commit comments