add mutex

pull/820/head
Fabrizio (Misto) Milo 2013-08-06 21:02:30 -07:00
parent d46748244f
commit 6fcb929318
1 changed files with 6 additions and 0 deletions

View File

@ -272,11 +272,15 @@ func (s *Server) QuorumSize() int {
// Retrieves the election timeout.
func (s *Server) ElectionTimeout() time.Duration {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.electionTimeout
}
// Sets the election timeout.
func (s *Server) SetElectionTimeout(duration time.Duration) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.electionTimeout = duration
}
@ -286,6 +290,8 @@ func (s *Server) SetElectionTimeout(duration time.Duration) {
// Retrieves the heartbeat timeout.
func (s *Server) HeartbeatTimeout() time.Duration {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.heartbeatTimeout
}