diff options
Diffstat (limited to 'Godeps/_workspace/src/github.com/pborman/uuid/node.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/node.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/node.go b/Godeps/_workspace/src/github.com/pborman/uuid/node.go index dd0a8ac18..42d60da8f 100644 --- a/Godeps/_workspace/src/github.com/pborman/uuid/node.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/node.go @@ -4,9 +4,13 @@ package uuid -import "net" +import ( + "net" + "sync" +) var ( + nodeMu sync.Mutex interfaces []net.Interface // cached list of interfaces ifname string // name of interface being used nodeID []byte // hardware for version 1 UUIDs @@ -16,6 +20,8 @@ var ( // derived. The interface "user" is returned if the NodeID was set by // SetNodeID. func NodeInterface() string { + defer nodeMu.Unlock() + nodeMu.Lock() return ifname } @@ -26,6 +32,12 @@ func NodeInterface() string { // // SetNodeInterface never fails when name is "". func SetNodeInterface(name string) bool { + defer nodeMu.Unlock() + nodeMu.Lock() + return setNodeInterface(name) +} + +func setNodeInterface(name string) bool { if interfaces == nil { var err error interfaces, err = net.Interfaces() @@ -59,8 +71,10 @@ func SetNodeInterface(name string) bool { // NodeID returns a slice of a copy of the current Node ID, setting the Node ID // if not already set. func NodeID() []byte { + defer nodeMu.Unlock() + nodeMu.Lock() if nodeID == nil { - SetNodeInterface("") + setNodeInterface("") } nid := make([]byte, 6) copy(nid, nodeID) @@ -71,6 +85,8 @@ func NodeID() []byte { // of id are used. If id is less than 6 bytes then false is returned and the // Node ID is not set. func SetNodeID(id []byte) bool { + defer nodeMu.Unlock() + nodeMu.Lock() if setNodeID(id) { ifname = "user" return true |