containerd/vendor/github.com/containerd/containerd/content/locks.go
Lantao Liu e887ef63d1 Upgrade containerd to 8ed1e24ae9.
Signed-off-by: Lantao Liu <lantaol@google.com>
2017-06-19 18:29:00 +00:00

38 lines
555 B
Go

package content
import (
"sync"
"github.com/pkg/errors"
)
// Handles locking references
// TODO: use boltdb for lock status
var (
// locks lets us lock in process
locks = map[string]struct{}{}
locksMu sync.Mutex
)
func tryLock(ref string) error {
locksMu.Lock()
defer locksMu.Unlock()
if _, ok := locks[ref]; ok {
return errors.Wrapf(ErrLocked, "key %s is locked", ref)
}
locks[ref] = struct{}{}
return nil
}
func unlock(ref string) {
locksMu.Lock()
defer locksMu.Unlock()
if _, ok := locks[ref]; ok {
delete(locks, ref)
}
}