atomic_value_go13.go 452 B

1234567891011121314151617181920212223242526272829
  1. // +build !go1.4
  2. package ldap
  3. import (
  4. "sync"
  5. )
  6. // This is a helper type that emulates the use of the "sync/atomic.Value"
  7. // struct that's available in Go 1.4 and up.
  8. type atomicValue struct {
  9. value interface{}
  10. lock sync.RWMutex
  11. }
  12. func (av *atomicValue) Store(val interface{}) {
  13. av.lock.Lock()
  14. av.value = val
  15. av.lock.Unlock()
  16. }
  17. func (av *atomicValue) Load() interface{} {
  18. av.lock.RLock()
  19. ret := av.value
  20. av.lock.RUnlock()
  21. return ret
  22. }