Uh oh!
There was an error while loading. Please reload this page.
gh-112075: Add try-incref functions from nogil branch for use in dict thread safety - #114512
Conversation
9318df9 to
818fc5fCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| /* Tries to incref the object op and ensures that *src still points to it. */ | ||
| static inline int | ||
| _Py_TryAcquireObject(PyObject **src, PyObject *op) |
There was a problem hiding this comment.
I don't love this name, but I don't know what it should be called.
There was a problem hiding this comment.
I don't really have a better name either :P
There was a problem hiding this comment.
Maybe just _Py_TryIncref()? Also maybe rename src to ptr for consistency with the other functions here.
colesbury
left a comment
There was a problem hiding this comment.
A few minor suggestions, but otherwise LGTM.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| /* Tries to incref the object op and ensures that *src still points to it. */ | ||
| static inline int | ||
| _Py_TryAcquireObject(PyObject **src, PyObject *op) |
There was a problem hiding this comment.
Maybe just _Py_TryIncref()? Also maybe rename src to ptr for consistency with the other functions here.
colesbury/nogil@b6b12a9a94e Co-Authored-By: Sam Gross <colesbury@gmail.com>
…n dict thread safety (python#114512) * Bring in a subset of biased reference counting: colesbury/nogil@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>
…n dict thread safety (python#114512) * Bring in a subset of biased reference counting: colesbury/nogil@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>
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:
inlineto the force inline functions to avoid a warning, and switching from_Py_ALWAYS_INLINEtoPy_ALWAYS_INLINEas that's available_Py_REF_LOCAL_SHIFTas it doesn't exist yet (and is currently 0 in the 3.12 nogil branch anyway)ob_ref_sharedis currentlyPy_ssize_tand not uint32_t, so use that_PY_LIKELYdoesn't exist, so drop it_Py_ThreadLocalbecomes_Py_IsOwnedByCurrentThread_Py_IncRefTotalcalls.dictobjects thread-safe in--disable-gilbuilds #112075