status.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "sync"
  17. "time"
  18. )
  19. type Status struct {
  20. Since time.Time
  21. Failures []string
  22. RoundLimit int
  23. Cluster ClusterStatus
  24. cluster *cluster
  25. mu sync.Mutex // guards Round and Case
  26. Round int
  27. Case int
  28. }
  29. func (s *Status) setRound(r int) {
  30. s.mu.Lock()
  31. defer s.mu.Unlock()
  32. s.Round = r
  33. }
  34. func (s *Status) getRound() int {
  35. s.mu.Lock()
  36. defer s.mu.Unlock()
  37. return s.Round
  38. }
  39. func (s *Status) setCase(c int) {
  40. s.mu.Lock()
  41. defer s.mu.Unlock()
  42. s.Case = c
  43. }
  44. func (s *Status) getCase() int {
  45. s.mu.Lock()
  46. defer s.mu.Unlock()
  47. return s.Case
  48. }