]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: fix comment typo and shorten state.mu.Lock to state.Lock
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 14:35:43 +0000 (15:35 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 14:37:04 +0000 (15:37 +0100)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/device.go
device/peer.go

index 935f41bc7abbcc758564b672a700e1a034c25ba8..041739700fcbdb59c6d44f85d509dcf0d399d383 100644 (file)
@@ -24,9 +24,8 @@ type Device struct {
        state struct {
                // state holds the device's state. It is accessed atomically.
                // Use the device.deviceState method to read it.
-               // If state.mu is (r)locked, state is the current state of the device.
-               // Without state.mu (r)locked, state is either the current state
-               // of the device or the intended future state of the device.
+               // If state is not locked, state is the current state of the device.
+               // If state is locked, state is the current state or intended future state of the device.
                // For example, while executing a call to Up, state will be deviceStateUp.
                // There is no guarantee that that intended future state of the device
                // will become the actual state; Up can fail.
@@ -36,7 +35,7 @@ type Device struct {
                // stopping blocks until all inputs to Device have been closed.
                stopping sync.WaitGroup
                // mu protects state changes.
-               mu sync.Mutex
+               sync.Mutex
        }
 
        net struct {
@@ -145,8 +144,8 @@ func unsafeRemovePeer(device *Device, peer *Peer, key NoisePublicKey) {
 
 // changeState attempts to change the device state to match want.
 func (device *Device) changeState(want deviceState) {
-       device.state.mu.Lock()
-       defer device.state.mu.Unlock()
+       device.state.Lock()
+       defer device.state.Unlock()
        old := device.deviceState()
        if old == deviceStateClosed {
                // once closed, always closed
@@ -353,8 +352,8 @@ func (device *Device) RemoveAllPeers() {
 }
 
 func (device *Device) Close() {
-       device.state.mu.Lock()
-       defer device.state.mu.Unlock()
+       device.state.Lock()
+       defer device.state.Unlock()
        if device.isClosed() {
                return
        }
index 69238a67d1bb81f812106a2391b7ce8d6f787bbc..96481ee44c63de416014b5e68298f0ab6e0b9504 100644 (file)
@@ -52,7 +52,7 @@ type Peer struct {
        }
 
        state struct {
-               mu sync.Mutex // protects against concurrent Start/Stop
+               sync.Mutex // protects against concurrent Start/Stop
        }
 
        queue struct {
@@ -161,8 +161,8 @@ func (peer *Peer) Start() {
        }
 
        // prevent simultaneous start/stop operations
-       peer.state.mu.Lock()
-       defer peer.state.mu.Unlock()
+       peer.state.Lock()
+       defer peer.state.Unlock()
 
        if peer.isRunning.Get() {
                return
@@ -242,8 +242,8 @@ func (peer *Peer) ExpireCurrentKeypairs() {
 }
 
 func (peer *Peer) Stop() {
-       peer.state.mu.Lock()
-       defer peer.state.mu.Unlock()
+       peer.state.Lock()
+       defer peer.state.Unlock()
 
        if !peer.isRunning.Swap(false) {
                return