aboutsummaryrefslogtreecommitdiff
path: root/commitquery/queries_acquire.go
blob: a3aa0e58b3cb28d9f532e0fcaab1d57248f2a41e (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package commitquery

// acquire removes one worker from the idle pool or allocates one new worker.
func (queries *Queries) acquire() *query {
	queries.mu.Lock()
	defer queries.mu.Unlock()

	count := len(queries.idle)
	if count == 0 {
		return newQuery(queries.fetcher, queries.graph)
	}

	q := queries.idle[count-1]
	queries.idle = queries.idle[:count-1]

	return q
}