types.go 678 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) 2015 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. package monitor
  5. import (
  6. "strconv"
  7. "sync/atomic"
  8. )
  9. // Uint is a 64-bit unsigned integer variable that satisfies the Var interface.
  10. type Uint struct {
  11. i uint64
  12. }
  13. func (v *Uint) String() string {
  14. return strconv.FormatUint(atomic.LoadUint64(&v.i), 10)
  15. }
  16. // Add delta
  17. func (v *Uint) Add(delta uint64) {
  18. atomic.AddUint64(&v.i, delta)
  19. }
  20. // Get the uint64 stored in the Uint
  21. func (v *Uint) Get() uint64 {
  22. return atomic.LoadUint64(&v.i)
  23. }
  24. // Set value
  25. func (v *Uint) Set(value uint64) {
  26. atomic.StoreUint64(&v.i, value)
  27. }