Skip to content

Commit

Permalink
Merge pull request #1826 from mrunalp/fix_lock
Browse files Browse the repository at this point in the history
Use RWLock for containers
  • Loading branch information
k8s-ci-robot committed Oct 8, 2018
2 parents 3d6cfc4 + 7f02d44 commit 2bf5fe8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions oci/container.go
Expand Up @@ -39,7 +39,7 @@ type Container struct {
created bool
state *ContainerState
metadata *pb.ContainerMetadata
opLock sync.Locker
opLock sync.RWMutex
// this is the /var/run/storage/... directory, erased on reboot
bundlePath string
// this is the /var/lib/storage/... directory
Expand Down Expand Up @@ -100,7 +100,6 @@ func NewContainer(id string, name string, bundlePath string, logPath string, net
dir: dir,
state: state,
stopSignal: stopSignal,
opLock: new(sync.Mutex),
}
return c, nil
}
Expand Down Expand Up @@ -241,8 +240,8 @@ func (c *Container) Metadata() *pb.ContainerMetadata {

// State returns the state of the running container
func (c *Container) State() *ContainerState {
c.opLock.Lock()
defer c.opLock.Unlock()
c.opLock.RLock()
defer c.opLock.RUnlock()
return c.state
}

Expand Down

0 comments on commit 2bf5fe8

Please sign in to comment.