optimize lock of runtimeState stuct

This commit is contained in:
Ke Zhang
2016-08-03 13:19:22 +08:00
parent 4fdde68f78
commit e9b0454a9d

View File

@@ -23,7 +23,7 @@ import (
)
type runtimeState struct {
sync.Mutex
sync.RWMutex
lastBaseRuntimeSync time.Time
baseRuntimeSyncThreshold time.Duration
networkError error
@@ -57,8 +57,8 @@ func (s *runtimeState) setPodCIDR(cidr string) {
}
func (s *runtimeState) podCIDR() string {
s.Lock()
defer s.Unlock()
s.RLock()
defer s.RUnlock()
return s.cidr
}
@@ -69,8 +69,8 @@ func (s *runtimeState) setInitError(err error) {
}
func (s *runtimeState) errors() []string {
s.Lock()
defer s.Unlock()
s.RLock()
defer s.RUnlock()
var ret []string
if s.initError != nil {
ret = append(ret, s.initError.Error())