summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-02-09 22:08:32 (GMT)
committerGitHub <noreply@github.com>2024-02-09 22:08:32 (GMT)
commita3af3cb4f424034b56404704fdf8f18e8c0a9982 (patch)
tree62ee00ea8725669a67c0fb9f7d8692fedf55bbae /Objects/object.c
parenta225520af941fb125a4ede77a617501dfb8b46da (diff)
downloadcpython-a3af3cb4f424034b56404704fdf8f18e8c0a9982.zip
cpython-a3af3cb4f424034b56404704fdf8f18e8c0a9982.tar.gz
cpython-a3af3cb4f424034b56404704fdf8f18e8c0a9982.tar.bz2
gh-110481: Implement inter-thread queue for biased reference counting (#114824)
Biased reference counting maintains two refcount fields in each object: `ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two fields. In some cases, when refcounting operations are split across threads, the ob_ref_shared field can be negative (although the total refcount must be at least zero). In this case, the thread that decremented the refcount requests that the owning thread give up ownership and merge the refcount fields.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 37a4b7a..61e6131 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2,6 +2,7 @@
/* Generic object operations; and implementation of None */
#include "Python.h"
+#include "pycore_brc.h" // _Py_brc_queue_object()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
#include "pycore_context.h" // _PyContextTokenMissing_Type
@@ -344,15 +345,10 @@ _Py_DecRefSharedDebug(PyObject *o, const char *filename, int lineno)
&shared, new_shared));
if (should_queue) {
- // TODO: the inter-thread queue is not yet implemented. For now,
- // we just merge the refcount here.
#ifdef Py_REF_DEBUG
_Py_IncRefTotal(_PyInterpreterState_GET());
#endif
- Py_ssize_t refcount = _Py_ExplicitMergeRefcount(o, -1);
- if (refcount == 0) {
- _Py_Dealloc(o);
- }
+ _Py_brc_queue_object(o);
}
else if (new_shared == _Py_REF_MERGED) {
// refcount is zero AND merged