Files
go-zero/core/syncx/barrier.go

16 lines
261 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package syncx
import "sync"
2021-02-28 16:16:22 +08:00
// A Barrier is used to facility the barrier on a resource.
2020-07-26 17:09:05 +08:00
type Barrier struct {
lock sync.Mutex
}
2021-02-28 16:16:22 +08:00
// Guard guards the given fn on the resource.
2020-07-26 17:09:05 +08:00
func (b *Barrier) Guard(fn func()) {
b.lock.Lock()
defer b.lock.Unlock()
fn()
}