Skip to content

Commit

Permalink
release lock as soon as finish using
Browse files Browse the repository at this point in the history
Signed-off-by: lowang-bh <lhui_wang@163.com>
  • Loading branch information
lowang-bh committed Sep 19, 2023
1 parent 059f060 commit d65b779
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pkg/queue/cluster_queue_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,7 @@ func (c *clusterQueueBase) DumpInadmissible() (sets.Set[string], bool) {
}

func (c *clusterQueueBase) Snapshot() []*workload.Info {
c.rwm.RLock()
defer c.rwm.RUnlock()
totalLen := c.heap.Len() + len(c.inadmissibleWorkloads)
elements := make([]*workload.Info, 0, totalLen)
for _, e := range c.heap.List() {
info := e.(*workload.Info)
elements = append(elements, info)
}
for _, e := range c.inadmissibleWorkloads {
elements = append(elements, e)
}
elements := c.totalElements()
sort.Slice(elements, func(i, j int) bool {
return queueOrdering(elements[i], elements[j])
})
Expand All @@ -271,3 +261,18 @@ func (c *clusterQueueBase) Info(key string) *workload.Info {
}
return info.(*workload.Info)
}

func (c *clusterQueueBase) totalElements() []*workload.Info {
c.rwm.RLock()
defer c.rwm.RUnlock()
totalLen := c.heap.Len() + len(c.inadmissibleWorkloads)
elements := make([]*workload.Info, 0, totalLen)
for _, e := range c.heap.List() {
info := e.(*workload.Info)
elements = append(elements, info)
}
for _, e := range c.inadmissibleWorkloads {
elements = append(elements, e)
}
return elements
}

0 comments on commit d65b779

Please sign in to comment.