Skip to content

Commit f3a21a7

Browse files
committed
gh-92810: Use FT atomic wrappers for ABC invalidation counter
1 parent cd097ab commit f3a21a7

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Include/internal/pycore_pyatomic_ft_wrappers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ extern "C" {
115115
_Py_atomic_load_ullong_relaxed(&value)
116116
#define FT_ATOMIC_ADD_SSIZE(value, new_value) \
117117
(void)_Py_atomic_add_ssize(&value, new_value)
118+
#define FT_ATOMIC_ADD_UINT64(value, new_value) \
119+
(void)_Py_atomic_add_uint64(&value, new_value)
118120

119121
#else
120122
#define FT_ATOMIC_LOAD_PTR(value) value

Modules/_abc.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,13 @@ get_abc_state(PyObject *module)
3535
static inline uint64_t
3636
get_invalidation_counter(_abcmodule_state *state)
3737
{
38-
#ifdef Py_GIL_DISABLED
39-
return _Py_atomic_load_uint64(&state->abc_invalidation_counter);
40-
#else
41-
return state->abc_invalidation_counter;
42-
#endif
38+
return FT_ATOMIC_LOAD_UINT64_RELAXED(state->abc_invalidation_counter);
4339
}
4440

4541
static inline void
4642
increment_invalidation_counter(_abcmodule_state *state)
4743
{
48-
#ifdef Py_GIL_DISABLED
49-
_Py_atomic_add_uint64(&state->abc_invalidation_counter, 1);
50-
#else
51-
state->abc_invalidation_counter++;
52-
#endif
44+
FT_ATOMIC_ADD_UINT64(state->abc_invalidation_counter, 1);
5345
}
5446

5547
/* This object stores internal state for ABCs.

0 commit comments

Comments
 (0)