tailscale/util/ctxlock/ctx_unchecked.go
Nick Khyl 968e921deb
util/ctxlock: make ctxlock.Context generic
Updates #12614
Updates #15824

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-05-01 10:52:59 -05:00

31 lines
691 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// This file exports optimized implementations of the [Context] that omit runtime checks.
// It is used when the build tag ts_omit_ctxlock_checks is set.
//go:build ts_omit_ctxlock_checks
package ctxlock
import (
"context"
"sync"
)
type Context[T sync.Locker] struct {
unchecked[T]
}
func None[T sync.Locker]() Context[T] {
return Context[T]{noneUnchecked[T]()}
}
func Wrap[T sync.Locker](parent context.Context) Context[T] {
return Context[T]{wrapUnchecked[T](parent)}
}
func Lock[T, P sync.Locker](parent Context[P], mu T) Context[T] {
return Context[T]{lockUnchecked(parent.unchecked, mu)}
}