Avoid unnecessary locking on runtimeImplMap
@@ -302,11 +302,14 @@ func (r *Runtime) StopContainer(ctx context.Context, c *Container, timeout int64
// DeleteContainer deletes a container.
func (r *Runtime) DeleteContainer(c *Container) (err error) {
- impl, err := r.RuntimeImpl(c)
- if err != nil {
+ r.runtimeImplMapMutex.RLock()
+ impl, ok := r.runtimeImplMap[c.ID()]
+ r.runtimeImplMapMutex.RUnlock()
+ if !ok {
+ if impl, err = r.newRuntimeImpl(c); err != nil {
return err
}
-
+ } else {
defer func() {
if err == nil {
r.runtimeImplMapMutex.Lock()
@@ -314,6 +317,7 @@ func (r *Runtime) DeleteContainer(c *Container) (err error) {
r.runtimeImplMapMutex.Unlock()
}
}()
+ }
return impl.DeleteContainer(c)
}
