mirror of https://github.com/k3s-io/k3s
pkg/controller/garbagecollector: simplify mutexes.
Similar to #29598, we can rely on the zero-value construction behavior to embed `sync.Mutex` into parent structs.pull/6/head
parent
37d3d390df
commit
1ca99119fd
|
@ -67,7 +67,7 @@ func (s objectReference) String() string {
|
||||||
type node struct {
|
type node struct {
|
||||||
identity objectReference
|
identity objectReference
|
||||||
// dependents will be read by the orphan() routine, we need to protect it with a lock.
|
// dependents will be read by the orphan() routine, we need to protect it with a lock.
|
||||||
dependentsLock *sync.RWMutex
|
dependentsLock sync.RWMutex
|
||||||
dependents map[*node]struct{}
|
dependents map[*node]struct{}
|
||||||
// When processing an Update event, we need to compare the updated
|
// When processing an Update event, we need to compare the updated
|
||||||
// ownerReferences with the owners recorded in the graph.
|
// ownerReferences with the owners recorded in the graph.
|
||||||
|
@ -151,7 +151,6 @@ func (p *Propagator) addDependentToOwners(n *node, owners []metatypes.OwnerRefer
|
||||||
OwnerReference: owner,
|
OwnerReference: owner,
|
||||||
Namespace: n.identity.Namespace,
|
Namespace: n.identity.Namespace,
|
||||||
},
|
},
|
||||||
dependentsLock: &sync.RWMutex{},
|
|
||||||
dependents: make(map[*node]struct{}),
|
dependents: make(map[*node]struct{}),
|
||||||
}
|
}
|
||||||
p.uidToNode.Write(ownerNode)
|
p.uidToNode.Write(ownerNode)
|
||||||
|
@ -378,7 +377,6 @@ func (p *Propagator) processEvent() {
|
||||||
},
|
},
|
||||||
Namespace: accessor.GetNamespace(),
|
Namespace: accessor.GetNamespace(),
|
||||||
},
|
},
|
||||||
dependentsLock: &sync.RWMutex{},
|
|
||||||
dependents: make(map[*node]struct{}),
|
dependents: make(map[*node]struct{}),
|
||||||
owners: accessor.GetOwnerReferences(),
|
owners: accessor.GetOwnerReferences(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,7 @@ func TestDependentsRace(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const updates = 100
|
const updates = 100
|
||||||
owner := &node{dependentsLock: &sync.RWMutex{}, dependents: make(map[*node]struct{})}
|
owner := &node{dependents: make(map[*node]struct{})}
|
||||||
ownerUID := types.UID("owner")
|
ownerUID := types.UID("owner")
|
||||||
gc.propagator.uidToNode.Write(owner)
|
gc.propagator.uidToNode.Write(owner)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in New Issue