mirror of https://github.com/tidwall/tile38.git
Lock refactoring
This commit is contained in:
parent
f0fb28c68d
commit
69b62e97e3
|
@ -230,35 +230,32 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener, http
|
|||
}
|
||||
|
||||
func (c *Controller) watchGC() {
|
||||
var elapsed uint64
|
||||
t := time.NewTicker(time.Second)
|
||||
defer t.Stop()
|
||||
|
||||
s := time.Now()
|
||||
for range t.C {
|
||||
elapsed++
|
||||
c.mu.RLock()
|
||||
|
||||
if c.stopWatchingAutoGC {
|
||||
c.mu.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
autoGC := c.config.AutoGC
|
||||
c.mu.RUnlock()
|
||||
|
||||
func() {
|
||||
if autoGC == 0 {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
if c.stopWatchingAutoGC {
|
||||
return
|
||||
if time.Now().Sub(s) < time.Second*time.Duration(autoGC) {
|
||||
continue
|
||||
}
|
||||
|
||||
if elapsed < autoGC {
|
||||
return
|
||||
}
|
||||
|
||||
c.mu.RLock()
|
||||
runtime.GC()
|
||||
debug.FreeOSMemory()
|
||||
c.mu.RUnlock()
|
||||
elapsed = 0
|
||||
}()
|
||||
s = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue