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