Documentation
¶
Index ¶
Constants ¶
const ( // BreakerGILDropRequest is set when another thread wants the GIL. BreakerGILDropRequest uint32 = 1 << 0 // BreakerSignalsPending is set when a Unix signal arrived. BreakerSignalsPending uint32 = 1 << 1 // BreakerCallsPending is set when Pending.Add queued a callback. BreakerCallsPending uint32 = 1 << 2 // BreakerAsyncException is set by PyThreadState_SetAsyncExc. BreakerAsyncException uint32 = 1 << 3 // BreakerGCScheduled is set when the cycle collector wants to run. BreakerGCScheduled uint32 = 1 << 4 // BreakerPleaseStop asks the eval loop to bail (interpreter shutdown). BreakerPleaseStop uint32 = 1 << 5 // BreakerExplicitMerge is the free-threaded build's per-thread // QSBR merge bit. No-op in v0.6. BreakerExplicitMerge uint32 = 1 << 6 // BreakerJITInvalidateCold is the JIT's cold-code invalidation // bit. No-op in v0.6 (no JIT). BreakerJITInvalidateCold uint32 = 1 << 7 // BreakerEventsMask is the mask of all currently defined event // bits. CPython reserves the low 8 bits. BreakerEventsMask uint32 = (1 << 8) - 1 )
const PendingQueueSize = 32
PendingQueueSize is the bounded ring-buffer capacity.
CPython: Include/cpython/ceval.h NPENDINGCALLS (32)
Variables ¶
var ErrPendingFull = errors.New("gil: pending-call queue full")
ErrPendingFull is returned by Add when the queue is full.
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker holds the eval-loop poll bits. One per Thread.
func (*Breaker) Clear ¶
Clear turns off the named bit.
CPython: Include/internal/pycore_ceval.h _Py_unset_eval_breaker_bit
type GIL ¶
type GIL struct {
// contains filtered or unexported fields
}
GIL is the per-interpreter execution lock.
func (*GIL) Acquire ¶
func (g *GIL) Acquire(ts holderID)
Acquire blocks until ts holds the GIL. Pass any opaque per-thread pointer for ts; the GIL only uses it for ownership checks.
CPython: Python/ceval_gil.c take_gil
func (*GIL) DropRequested ¶
DropRequested reports whether another goroutine asked the holder to drop. Cheap atomic read.
func (*GIL) Holder ¶
func (g *GIL) Holder() holderID
Holder returns the current holder (or nil). Read with the lock held; useful only for diagnostics.
func (*GIL) Release ¶
func (g *GIL) Release(ts holderID)
Release drops the GIL. Mismatched releases panic to surface lock inversion bugs early.
CPython: Python/ceval_gil.c drop_gil
func (*GIL) RequestDrop ¶
func (g *GIL) RequestDrop()
RequestDrop marks the GIL as wanting to be dropped at the next poll point. The eval loop checks DropRequested on each iteration and releases voluntarily when set.
CPython: Python/ceval_gil.c COMPUTE_EVAL_BREAKER (gil-drop bit)
func (*GIL) SetSwitchInterval ¶
SetSwitchInterval updates the cooperative-yield interval.
CPython: Python/sysmodule.c sys_setswitchinterval
func (*GIL) SwitchInterval ¶
SwitchInterval returns the cooperative-yield interval.
CPython: Python/sysmodule.c sys_getswitchinterval
type Pending ¶
type Pending struct {
// contains filtered or unexported fields
}
Pending is a per-interpreter ring buffer of callbacks.
func (*Pending) Add ¶
func (p *Pending) Add(fn PendingFunc) error
Add enqueues fn. Returns ErrPendingFull if the queue is at capacity. Existing entries are not lost on overflow.
CPython: Python/ceval_gil.c _Py_AddPendingCall
type PendingFunc ¶
type PendingFunc func() error
PendingFunc is a callback to run on the eval-loop thread.
type SignalBridge ¶
type SignalBridge struct {
// contains filtered or unexported fields
}
SignalBridge wires os/signal delivery to a Breaker and a Pending queue. One per interpreter.
func NewSignalBridge ¶
func NewSignalBridge(b *Breaker, p *Pending) *SignalBridge
NewSignalBridge constructs an unstarted bridge.
func (*SignalBridge) Handle ¶
func (s *SignalBridge) Handle(sig os.Signal, fn PendingFunc)
Handle registers fn to run (under the GIL, at the next poll point) when sig arrives. Replaces any previous handler for sig.
CPython: Modules/signalmodule.c signal_signal_impl
func (*SignalBridge) Stop ¶
func (s *SignalBridge) Stop()
Stop tears the bridge down. Any in-flight signal that has been dispatched to the channel still triggers its handler.
func (*SignalBridge) Unhandle ¶
func (s *SignalBridge) Unhandle(sig os.Signal)
Unhandle stops receiving sig.