From b028371e0aa522529fc25fbbf1e5f0898e74a9e1 Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Wed, 27 May 2015 21:40:02 +0000 Subject: [PATCH] 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 --- sandbox/namespace_linux.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sandbox/namespace_linux.go b/sandbox/namespace_linux.go index af1efc1..598570a 100644 --- a/sandbox/namespace_linux.go +++ b/sandbox/namespace_linux.go @@ -55,9 +55,7 @@ func createBasePath() { } func removeUnusedPaths() { - for { - time.Sleep(time.Duration(gpmCleanupPeriod)) - + for range time.Tick(gpmCleanupPeriod) { gpmLock.Lock() pathList := make([]string, 0, len(garbagePathMap)) for path := range garbagePathMap { @@ -78,13 +76,13 @@ func removeUnusedPaths() { func addToGarbagePaths(path string) { gpmLock.Lock() garbagePathMap[path] = true - defer gpmLock.Unlock() + gpmLock.Unlock() } func removeFromGarbagePaths(path string) { gpmLock.Lock() delete(garbagePathMap, path) - defer gpmLock.Unlock() + gpmLock.Unlock() } // GenerateKey generates a sandbox key based on the passed