mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
bd5ceb5142
Signed-off-by: Anders Eknert <anders@styra.com>
39 lines
604 B
Go
39 lines
604 B
Go
// Copyright 2024 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package debug
|
|
|
|
import "sync"
|
|
|
|
type latch struct {
|
|
paused bool
|
|
waitGroup sync.WaitGroup
|
|
lock sync.Mutex
|
|
}
|
|
|
|
func (l *latch) block() {
|
|
l.lock.Lock()
|
|
defer l.lock.Unlock()
|
|
if !l.paused {
|
|
l.waitGroup.Add(1)
|
|
l.paused = true
|
|
}
|
|
}
|
|
|
|
func (l *latch) unblock() {
|
|
l.lock.Lock()
|
|
defer l.lock.Unlock()
|
|
if l.paused {
|
|
l.waitGroup.Done()
|
|
l.paused = false
|
|
}
|
|
}
|
|
|
|
func (l *latch) wait() {
|
|
l.waitGroup.Wait()
|
|
}
|
|
|
|
func (*latch) Close() {
|
|
}
|