Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sync.RWMutex for VXLANUDPPort #2302

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions drivers/overlay/overlayutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

var (
mutex sync.RWMutex
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to explain this change; it's convention to put the mutex above the variables that it's protecting

vxlanUDPPort uint32
mutex sync.Mutex
)

const defaultVXLANUDPPort = 4789
Expand All @@ -19,8 +19,6 @@ func init() {

// ConfigVXLANUDPPort configures vxlan udp port number.
func ConfigVXLANUDPPort(vxlanPort uint32) error {
mutex.Lock()
defer mutex.Unlock()
// if the value comes as 0 by any reason we set it to default value 4789
if vxlanPort == 0 {
vxlanPort = defaultVXLANUDPPort
Expand All @@ -33,14 +31,15 @@ func ConfigVXLANUDPPort(vxlanPort uint32) error {
if vxlanPort < 1024 || vxlanPort > 49151 {
return fmt.Errorf("ConfigVxlanUDPPort Vxlan UDP port number is not in valid range %d", vxlanPort)
}
mutex.Lock()
vxlanUDPPort = vxlanPort

mutex.Unlock()
return nil
}

// VXLANUDPPort returns Vxlan UDP port number
func VXLANUDPPort() uint32 {
mutex.Lock()
defer mutex.Unlock()
mutex.RLock()
defer mutex.RUnlock()
return vxlanUDPPort
}