Reworkkgarbage collection code to use tick

Instead of sleeping reworked the code to use recurring ticks.
Also cleaned up unnecessary defers.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-05-27 21:40:02 +00:00 committed by Madhu Venugopal
parent f429a2528d
commit 7560ca63f5

View file

@ -56,9 +56,7 @@ func createBasePath() {
} }
func removeUnusedPaths() { func removeUnusedPaths() {
for { for range time.Tick(gpmCleanupPeriod) {
time.Sleep(time.Duration(gpmCleanupPeriod))
gpmLock.Lock() gpmLock.Lock()
pathList := make([]string, 0, len(garbagePathMap)) pathList := make([]string, 0, len(garbagePathMap))
for path := range garbagePathMap { for path := range garbagePathMap {
@ -79,13 +77,13 @@ func removeUnusedPaths() {
func addToGarbagePaths(path string) { func addToGarbagePaths(path string) {
gpmLock.Lock() gpmLock.Lock()
garbagePathMap[path] = true garbagePathMap[path] = true
defer gpmLock.Unlock() gpmLock.Unlock()
} }
func removeFromGarbagePaths(path string) { func removeFromGarbagePaths(path string) {
gpmLock.Lock() gpmLock.Lock()
delete(garbagePathMap, path) delete(garbagePathMap, path)
defer gpmLock.Unlock() gpmLock.Unlock()
} }
// GenerateKey generates a sandbox key based on the passed // GenerateKey generates a sandbox key based on the passed