Lock refactoring

This commit is contained in:
w1n2k 2017-01-20 12:09:39 +03:00
parent f0fb28c68d
commit 69b62e97e3
1 changed files with 16 additions and 19 deletions

View File

@ -230,35 +230,32 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener, http
} }
func (c *Controller) watchGC() { func (c *Controller) watchGC() {
var elapsed uint64
t := time.NewTicker(time.Second) t := time.NewTicker(time.Second)
defer t.Stop() defer t.Stop()
s := time.Now()
for range t.C { for range t.C {
elapsed++
c.mu.RLock() c.mu.RLock()
if c.stopWatchingAutoGC {
c.mu.RUnlock()
return
}
autoGC := c.config.AutoGC autoGC := c.config.AutoGC
c.mu.RUnlock() c.mu.RUnlock()
func() { if autoGC == 0 {
if autoGC == 0 { continue
return }
}
if c.stopWatchingAutoGC { if time.Now().Sub(s) < time.Second*time.Duration(autoGC) {
return continue
} }
if elapsed < autoGC { runtime.GC()
return debug.FreeOSMemory()
} s = time.Now()
c.mu.RLock()
runtime.GC()
debug.FreeOSMemory()
c.mu.RUnlock()
elapsed = 0
}()
} }
} }