Lines Matching refs:g
31 func (g *Gate) Enter() int {
32 g.cv.L.Lock()
33 for g.busy[g.pos] || g.stop {
34 g.cv.Wait()
36 idx := g.pos
37 g.pos++
38 if g.pos >= len(g.busy) {
39 g.pos = 0
41 g.busy[idx] = true
42 g.running++
43 if g.running > len(g.busy) {
46 g.cv.L.Unlock()
50 func (g *Gate) Leave(idx int) {
51 g.cv.L.Lock()
52 if !g.busy[idx] {
55 g.busy[idx] = false
56 g.running--
57 if g.running < 0 {
60 if idx == 0 && g.f != nil {
61 if g.stop {
64 g.stop = true
65 for g.running != 0 {
66 g.cv.Wait()
68 g.stop = false
69 g.f()
70 g.cv.Broadcast()
72 if idx == g.pos && !g.stop || g.running == 0 && g.stop {
73 g.cv.Broadcast()
75 g.cv.L.Unlock()