mirror of https://github.com/docker/docs.git
inherit from sync
This commit is contained in:
parent
8390cc6ef7
commit
a913f40d39
10
cluster.go
10
cluster.go
|
@ -11,7 +11,7 @@ var (
|
|||
)
|
||||
|
||||
type Cluster struct {
|
||||
mux sync.Mutex
|
||||
sync.Mutex
|
||||
nodes map[string]*Node
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@ func (c *Cluster) AddNode(n *Node) error {
|
|||
return ErrNodeNotConnected
|
||||
}
|
||||
|
||||
c.mux.Lock()
|
||||
defer c.mux.Unlock()
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if _, exists := c.nodes[n.ID]; exists {
|
||||
return ErrNodeAlreadyRegistered
|
||||
|
@ -41,8 +41,8 @@ func (c *Cluster) AddNode(n *Node) error {
|
|||
|
||||
// Containers returns all the containers running in the cluster.
|
||||
func (c *Cluster) Containers() []*Container {
|
||||
c.mux.Lock()
|
||||
defer c.mux.Unlock()
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
out := []*Container{}
|
||||
for _, n := range c.nodes {
|
||||
|
|
11
node.go
11
node.go
|
@ -28,6 +28,8 @@ func NewNode(id string, addr string) *Node {
|
|||
}
|
||||
|
||||
type Node struct {
|
||||
sync.Mutex
|
||||
|
||||
ID string
|
||||
IP string
|
||||
Addr string
|
||||
|
@ -35,7 +37,6 @@ type Node struct {
|
|||
Memory int64
|
||||
Labels map[string]string
|
||||
|
||||
mux sync.Mutex
|
||||
ch chan bool
|
||||
containers map[string]*Container
|
||||
client dockerclient.Client
|
||||
|
@ -112,8 +113,8 @@ func (n *Node) updateState() error {
|
|||
return err
|
||||
}
|
||||
|
||||
n.mux.Lock()
|
||||
defer n.mux.Unlock()
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
|
||||
n.containers = make(map[string]*Container)
|
||||
for _, c := range containers {
|
||||
|
@ -199,8 +200,8 @@ func (n *Node) Remove(container *Container, force bool) error {
|
|||
|
||||
// Remove the container from the state. Eventually, the state refresh loop
|
||||
// will rewrite this.
|
||||
n.mux.Lock()
|
||||
defer n.mux.Unlock()
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
delete(n.containers, container.Id)
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue