Skip to content

Commit

Permalink
Use free-threaded atomic wrapper for loading deque_iter len
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Feb 14, 2024
1 parent b166202 commit 6e64ef4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Include/internal/pycore_pyatomic_ft_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ extern "C" {
#endif

#ifdef Py_GIL_DISABLED
#define FT_ATOMIC_LOAD_SSIZE(value) _Py_atomic_load_ssize(&value)
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) \
_Py_atomic_load_ssize_relaxed(&value)
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) \
_Py_atomic_store_ssize_relaxed(&value, new_value)
#else
#define FT_ATOMIC_LOAD_SSIZE(value) value
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) value
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) value = new_value
#endif
Expand Down
3 changes: 2 additions & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "pycore_dict.h" // _PyDict_GetItem_KnownHash()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pyatomic_ft_wrappers.h"
#include "pycore_typeobject.h" // _PyType_GetModuleState()

#include <stddef.h>
Expand Down Expand Up @@ -2007,7 +2008,7 @@ dequeiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject *
dequeiter_len(dequeiterobject *it, PyObject *Py_UNUSED(ignored))
{
Py_ssize_t len = _Py_atomic_load_ssize(&it->counter);
Py_ssize_t len = FT_ATOMIC_LOAD_SSIZE(it->counter);
return PyLong_FromSsize_t(len);
}

Expand Down

0 comments on commit 6e64ef4

Please sign in to comment.