Skip to content

Commit

Permalink
pythongh-112075: Add gc shared bits (python#114931)
Browse files Browse the repository at this point in the history
Add GC shared flags for objects to the GC bit states in free-threaded builds
  • Loading branch information
DinoV authored Feb 5, 2024
1 parent 36518e6 commit bcccf1f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -68,6 +69,22 @@ static inline int _PyObject_GC_MAY_BE_TRACKED(PyObject *obj) {
return 1;
}

#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 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))

#endif

/* Bit flags for _gc_prev */
/* Bit 0 is set when tp_finalize is called */
Expand Down

0 comments on commit bcccf1f

Please sign in to comment.