|
|
@ -77,7 +77,7 @@ type StateSyncer struct {
|
|
|
|
|
|
|
|
|
|
|
|
// paused stores whether sync runs are temporarily disabled.
|
|
|
|
// paused stores whether sync runs are temporarily disabled.
|
|
|
|
pauseLock sync.Mutex
|
|
|
|
pauseLock sync.Mutex
|
|
|
|
paused int
|
|
|
|
paused bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewStateSyner(state State, intv time.Duration, shutdownCh chan struct{}, logger *log.Logger) *StateSyncer {
|
|
|
|
func NewStateSyner(state State, intv time.Duration, shutdownCh chan struct{}, logger *log.Logger) *StateSyncer {
|
|
|
@ -180,7 +180,7 @@ FullSync:
|
|
|
|
func (s *StateSyncer) ifNotPausedRun(f func() error) error {
|
|
|
|
func (s *StateSyncer) ifNotPausedRun(f func() error) error {
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
defer s.pauseLock.Unlock()
|
|
|
|
defer s.pauseLock.Unlock()
|
|
|
|
if s.paused != 0 {
|
|
|
|
if s.paused {
|
|
|
|
return errPaused
|
|
|
|
return errPaused
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f()
|
|
|
|
return f()
|
|
|
@ -189,7 +189,10 @@ func (s *StateSyncer) ifNotPausedRun(f func() error) error {
|
|
|
|
// Pause temporarily disables sync runs.
|
|
|
|
// Pause temporarily disables sync runs.
|
|
|
|
func (s *StateSyncer) Pause() {
|
|
|
|
func (s *StateSyncer) Pause() {
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
s.paused++
|
|
|
|
if s.paused {
|
|
|
|
|
|
|
|
panic("pause while paused")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s.paused = true
|
|
|
|
s.pauseLock.Unlock()
|
|
|
|
s.pauseLock.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -197,18 +200,16 @@ func (s *StateSyncer) Pause() {
|
|
|
|
func (s *StateSyncer) Paused() bool {
|
|
|
|
func (s *StateSyncer) Paused() bool {
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
defer s.pauseLock.Unlock()
|
|
|
|
defer s.pauseLock.Unlock()
|
|
|
|
return s.paused != 0
|
|
|
|
return s.paused
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Resume re-enables sync runs.
|
|
|
|
// Resume re-enables sync runs.
|
|
|
|
func (s *StateSyncer) Resume() {
|
|
|
|
func (s *StateSyncer) Resume() {
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
s.pauseLock.Lock()
|
|
|
|
s.paused--
|
|
|
|
if !s.paused {
|
|
|
|
if s.paused < 0 {
|
|
|
|
panic("resume while not paused")
|
|
|
|
panic("unbalanced pause/resume")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.paused == 0 {
|
|
|
|
|
|
|
|
s.SyncChanges.Trigger()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.paused = false
|
|
|
|
s.pauseLock.Unlock()
|
|
|
|
s.pauseLock.Unlock()
|
|
|
|
|
|
|
|
s.SyncChanges.Trigger()
|
|
|
|
}
|
|
|
|
}
|
|
|
|