From 482e1a20b95daf97b68d10418da573743682ab60 Mon Sep 17 00:00:00 2001 From: Dino Viehland Date: Thu, 1 Feb 2024 13:43:07 -0800 Subject: [PATCH 1/2] Add gc shared bits --- Include/internal/pycore_gc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h index ca1d9fdf5253b8..0a8da4b21e5bdf 100644 --- a/Include/internal/pycore_gc.h +++ b/Include/internal/pycore_gc.h @@ -43,6 +43,7 @@ static inline PyObject* _Py_FROM_GC(PyGC_Head *gc) { # define _PyGC_BITS_FINALIZED (2) # define _PyGC_BITS_UNREACHABLE (4) # define _PyGC_BITS_FROZEN (8) +# define _PyGC_BITS_SHARED (16) #endif /* True if the object is currently tracked by the GC. */ @@ -68,6 +69,19 @@ static inline int _PyObject_GC_MAY_BE_TRACKED(PyObject *obj) { return 1; } +#ifdef Py_GIL_DISABLED + +static inline int _PyObject_GC_IS_SHARED(PyObject *op) { + return (op->ob_gc_bits & _PyGC_BITS_SHARED) != 0; +} +#define _PyObject_GC_IS_SHARED(op) _PyObject_GC_IS_SHARED(_Py_CAST(PyObject*, op)) + +static inline int _PyObject_GC_SET_SHARED(PyObject *op) { + return op->ob_gc_bits |= _PyGC_BITS_SHARED; +} +#define _PyObject_GC_SET_SHARED(op) _PyObject_GC_SET_SHARED(_Py_CAST(PyObject*, op)) + +#endif /* Bit flags for _gc_prev */ /* Bit 0 is set when tp_finalize is called */ From 582179c3cd4cae685fc22cda53ccb4bec0ce3735 Mon Sep 17 00:00:00 2001 From: Dino Viehland Date: Fri, 2 Feb 2024 17:08:42 -0800 Subject: [PATCH 2/2] GC shared doc and tweak --- Include/internal/pycore_gc.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h index 0a8da4b21e5bdf..8d0bc2a218e48d 100644 --- a/Include/internal/pycore_gc.h +++ b/Include/internal/pycore_gc.h @@ -71,13 +71,16 @@ static inline int _PyObject_GC_MAY_BE_TRACKED(PyObject *obj) { #ifdef Py_GIL_DISABLED +/* True if an object is shared between multiple threads and + * needs special purpose when freeing to do the possibility + * of in-flight lock-free reads occuring */ static inline int _PyObject_GC_IS_SHARED(PyObject *op) { return (op->ob_gc_bits & _PyGC_BITS_SHARED) != 0; } #define _PyObject_GC_IS_SHARED(op) _PyObject_GC_IS_SHARED(_Py_CAST(PyObject*, op)) -static inline int _PyObject_GC_SET_SHARED(PyObject *op) { - return op->ob_gc_bits |= _PyGC_BITS_SHARED; +static inline void _PyObject_GC_SET_SHARED(PyObject *op) { + op->ob_gc_bits |= _PyGC_BITS_SHARED; } #define _PyObject_GC_SET_SHARED(op) _PyObject_GC_SET_SHARED(_Py_CAST(PyObject*, op))