mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
github.com/argoproj/pkg/v2 was one of two live argoproj dependencies. It is 11 files and 176K total, and we used five packages from it: grpc/http, kubeclientmetrics, stats, sync, time. Vendored into util/vendored/ and the dependency dropped from go.mod, so the gRPC surface (2 references, in grpc-http/forwarders.go) is now ours to remove on our own schedule rather than upstream's. Kubernetes client-go pulls gRPC transitively regardless, so this is isolation — a realistic first step — not a claim that gRPC is gone. Internalized rather than forked to a shared repo because the only other consumer, hanzo/gitops, has zero live deployments and zero dependents. A second repo would be a second thing to version for one caller. NOTICE carries the Apache-2.0 attribution. go build ./... exit 0. Co-authored-by: Hanzo Dev <[email protected]>
60 lines
921 B
Go
60 lines
921 B
Go
package sync
|
|
|
|
import "sync"
|
|
|
|
type KeyLock interface {
|
|
Lock(key string)
|
|
Unlock(key string)
|
|
RLock(key string)
|
|
RUnlock(key string)
|
|
}
|
|
|
|
type keyLock struct {
|
|
guard sync.RWMutex
|
|
locks map[string]*sync.RWMutex
|
|
}
|
|
|
|
func NewKeyLock() KeyLock {
|
|
return &keyLock{
|
|
guard: sync.RWMutex{},
|
|
locks: map[string]*sync.RWMutex{},
|
|
}
|
|
}
|
|
|
|
func (l *keyLock) getLock(key string) *sync.RWMutex {
|
|
l.guard.RLock()
|
|
if lock, ok := l.locks[key]; ok {
|
|
l.guard.RUnlock()
|
|
return lock
|
|
}
|
|
|
|
l.guard.RUnlock()
|
|
l.guard.Lock()
|
|
|
|
if lock, ok := l.locks[key]; ok {
|
|
l.guard.Unlock()
|
|
return lock
|
|
}
|
|
|
|
lock := &sync.RWMutex{}
|
|
l.locks[key] = lock
|
|
l.guard.Unlock()
|
|
return lock
|
|
}
|
|
|
|
func (l *keyLock) Lock(key string) {
|
|
l.getLock(key).Lock()
|
|
}
|
|
|
|
func (l *keyLock) Unlock(key string) {
|
|
l.getLock(key).Unlock()
|
|
}
|
|
|
|
func (l *keyLock) RLock(key string) {
|
|
l.getLock(key).RLock()
|
|
}
|
|
|
|
func (l *keyLock) RUnlock(key string) {
|
|
l.getLock(key).RUnlock()
|
|
}
|