barrier.go 261 B

123456789101112131415
  1. package syncx
  2. import "sync"
  3. // A Barrier is used to facility the barrier on a resource.
  4. type Barrier struct {
  5. lock sync.Mutex
  6. }
  7. // Guard guards the given fn on the resource.
  8. func (b *Barrier) Guard(fn func()) {
  9. b.lock.Lock()
  10. defer b.lock.Unlock()
  11. fn()
  12. }