inherit from sync

This commit is contained in:
Victor Vieux 2014-11-11 01:54:48 +00:00
parent 8390cc6ef7
commit a913f40d39
2 changed files with 11 additions and 10 deletions

View File

@ -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
View File

@ -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