https://github.com/python/cpython/commit/bcccf1fb63870c1b7f8abe246e27b7fff343abd7
commit: bcccf1fb63870c1b7f8abe246e27b7fff343abd7
branch: main
author: Dino Viehland <[email protected]>
committer: DinoV <[email protected]>
date: 2024-02-05T10:35:59-08:00
summary:

gh-112075: Add gc shared bits (#114931)

Add GC shared flags for objects to the GC bit states in free-threaded builds

files:
M Include/internal/pycore_gc.h

diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h
index d2f5c69b45ee39..aeb07238fc8345 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,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 */

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to