brc

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package brc ports cpython/Python/brc.c. v0.3 ships only the field layout and no-op operations; the GIL build does not need biased reference counting. The free-threading build wires the queues in a later phase (see roadmap v0.14).

CPython: Python/brc.c file overview

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrainQueue

func DrainQueue(_ *ThreadState)

DrainQueue runs the owner-side drain step. v0.3 has nothing to drain; the loop body lands in v0.14.

CPython: Python/brc.c:L131 _Py_brc_merge_refcounts

func QueueRemote

func QueueRemote(_ *ThreadState, _ *QueuedObject)

QueueRemote enqueues obj on the owner's remote queue. In the GIL build this is a no-op because every thread shares one refcount. In the free-threading build (v0.14) this walks the lock-free push path from CPython.

CPython: Python/brc.c:L66 _Py_brc_queue_object

Types

type QueuedObject

type QueuedObject struct {
	Next *QueuedObject
}

QueuedObject is the link entry that a remote thread pushes onto an owner's biased-refcount queue when it decrements an object that the owner allocated. The owner drains its own queue without atomics.

CPython: Include/internal/pycore_brc.h:L29 _PyObjectQueue

type ThreadState

type ThreadState struct {
	LocalQueue  *QueuedObject
	RemoteQueue atomic.Pointer[QueuedObject]
	QueueMutex  uint32
	TID         uint64
}

ThreadState is the per-thread biased-refcount slot. Each Python thread embeds one of these in its state.Thread (wired up in v0.14). The owner pushes "merged" decrements into LocalQueue; remote threads push into RemoteQueue, which the owner drains under QueueMutex.

CPython: Include/internal/pycore_brc.h:L57 _Py_brc_per_thread_state

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL