Documentation
¶
Overview ¶
Package yieldpoint provides cooperative goroutine yielding based on priority-aware scheduling.
Index ¶
- Variables
- func EnterHighPriority()
- func ExitHighPriority()
- func IsHighPriorityActive() bool
- func MaybeYield()
- func MaybeYieldFast()
- func MaybeYieldWithContext(ctx context.Context) error
- func SetDefaultYieldDuration(d time.Duration)
- func SetSpinWaitIterations(n int)
- func WaitIfActive()
- func WaitIfActiveFast()
- func WaitIfActiveWithContext(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var Cond = sync.NewCond(&Mu)
Cond is the condition variable used for efficient blocking
var DefaultYieldDuration = 1 * time.Millisecond
DefaultYieldDuration is the default duration to sleep when yielding
var HighPriorityCount atomic.Int32
HighPriorityCount tracks the number of active high-priority sections
var Mu sync.Mutex
Mu is the mutex used for efficient blocking in WaitIfActive
var SpinWaitIterations = 1000
SpinWaitIterations is the number of iterations to spin-wait before falling back to mutex-based waiting
Functions ¶
func EnterHighPriority ¶
func EnterHighPriority()
EnterHighPriority begins a high-priority section. Multiple calls are supported through reference counting.
func ExitHighPriority ¶
func ExitHighPriority()
ExitHighPriority ends a high-priority section. If this is the last high-priority section, it will signal any waiting goroutines.
func IsHighPriorityActive ¶
func IsHighPriorityActive() bool
IsHighPriorityActive returns true if any high-priority sections are currently active.
func MaybeYield ¶
func MaybeYield()
MaybeYield voluntarily yields the current goroutine if any high-priority sections are active. This is a non-blocking operation that uses runtime.Gosched() combined with a small sleep to ensure effective processor yielding.
func MaybeYieldFast ¶
func MaybeYieldFast()
MaybeYieldFast is a high-performance version of MaybeYield that avoids time.Sleep and uses only runtime.Gosched() for minimal overhead. This is suitable for performance-critical code paths where the exact timing of yields is less important.
func MaybeYieldWithContext ¶
MaybeYieldWithContext is a context-aware version of MaybeYield
func SetDefaultYieldDuration ¶
SetDefaultYieldDuration sets the default duration to sleep when yielding
func SetSpinWaitIterations ¶
func SetSpinWaitIterations(n int)
SetSpinWaitIterations sets the number of iterations to spin-wait before falling back to mutex-based waiting
func WaitIfActive ¶
func WaitIfActive()
WaitIfActive blocks the current goroutine until no high-priority sections are active. This is an efficient blocking operation that uses sync.Cond to avoid busy waiting.
func WaitIfActiveFast ¶
func WaitIfActiveFast()
WaitIfActiveFast is a high-performance version of WaitIfActive that uses a spin-wait strategy before falling back to mutex-based waiting. This is suitable for performance-critical code paths where the wait time is expected to be very short.
func WaitIfActiveWithContext ¶
WaitIfActiveWithContext is a context-aware version of WaitIfActive
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic_usage
command
|
|
|
concurrent_yielding
command
|
|
|
context_support
command
|
|
|
fast
command
|
|
|
nested_priority
command
|
|
|
wait_if_active
command
|