]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-112075: Add try-incref functions from nogil branch for use in dict thread safety...
authorDino Viehland <dinoviehland@meta.com>
Thu, 25 Jan 2024 17:34:03 +0000 (09:34 -0800)
committerGitHub <noreply@github.com>
Thu, 25 Jan 2024 17:34:03 +0000 (09:34 -0800)
commit4850410b60183dac021ded219a49be140fe5fefe
tree4487d9e47b04e4dbde2fa33c8d6980466f62574f
parent8278fa2f5625b41be91191d18ee8eeab904a54ff
gh-112075: Add try-incref functions from nogil branch for use in dict thread safety (#114512)

* Bring in a subset of biased reference counting:
https://github.com/colesbury/nogil/commit/b6b12a9a94e

The NoGIL branch has functions for attempting to do an incref on an object which may or may not be in flight. This just brings those functions over so that they will be usable from in the dict implementation to get items w/o holding a lock.

There's a handful of small simple modifications:

    Adding inline to the force inline functions to avoid a warning, and switching from _Py_ALWAYS_INLINE to Py_ALWAYS_INLINE as that's available
    Remove _Py_REF_LOCAL_SHIFT as it doesn't exist yet (and is currently 0 in the 3.12 nogil branch anyway)
    ob_ref_shared is currently Py_ssize_t and not uint32_t, so use that
    _PY_LIKELY doesn't exist, so drop it
    _Py_ThreadLocal becomes _Py_IsOwnedByCurrentThread
    Add '_PyInterpreterState_GET()' to _Py_IncRefTotal calls.

Co-Authored-By: Sam Gross <colesbury@gmail.com>
Include/internal/pycore_object.h