]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Removed debugging locks
authorMathias Hall-Andersen <mathias@hall-andersen.dk>
Sun, 4 Feb 2018 15:46:24 +0000 (16:46 +0100)
committerMathias Hall-Andersen <mathias@hall-andersen.dk>
Sun, 4 Feb 2018 15:46:24 +0000 (16:46 +0100)
device.go
peer.go

index c0419877ea85130cf75f65834bcb4e54d4d84a58..22e0990f64d58bc48902d01d24960731c4ad4342 100644 (file)
--- a/device.go
+++ b/device.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-       "github.com/sasha-s/go-deadlock"
        "runtime"
        "sync"
        "sync/atomic"
@@ -16,31 +15,31 @@ type Device struct {
        // synchronized resources (locks acquired in order)
 
        state struct {
-               mutex    deadlock.Mutex
+               mutex    sync.Mutex
                changing AtomicBool
                current  bool
        }
 
        net struct {
-               mutex  deadlock.RWMutex
+               mutex  sync.RWMutex
                bind   Bind   // bind interface
                port   uint16 // listening port
                fwmark uint32 // mark value (0 = disabled)
        }
 
        noise struct {
-               mutex      deadlock.RWMutex
+               mutex      sync.RWMutex
                privateKey NoisePrivateKey
                publicKey  NoisePublicKey
        }
 
        routing struct {
-               mutex deadlock.RWMutex
+               mutex sync.RWMutex
                table RoutingTable
        }
 
        peers struct {
-               mutex  deadlock.RWMutex
+               mutex  sync.RWMutex
                keyMap map[NoisePublicKey]*Peer
        }
 
@@ -101,53 +100,46 @@ func deviceUpdateState(device *Device) {
                return
        }
 
-       func() {
+       // compare to current state of device
 
-               // compare to current state of device
-
-               device.state.mutex.Lock()
-               defer device.state.mutex.Unlock()
-
-               newIsUp := device.isUp.Get()
-
-               if newIsUp == device.state.current {
-                       device.state.changing.Set(false)
-                       return
-               }
-
-               // change state of device
-
-               switch newIsUp {
-               case true:
-                       if err := device.BindUpdate(); err != nil {
-                               device.isUp.Set(false)
-                               break
-                       }
+       device.state.mutex.Lock()
 
-                       device.peers.mutex.Lock()
-                       defer device.peers.mutex.Unlock()
+       newIsUp := device.isUp.Get()
 
-                       for _, peer := range device.peers.keyMap {
-                               peer.Start()
-                       }
+       if newIsUp == device.state.current {
+               device.state.changing.Set(false)
+               device.state.mutex.Unlock()
+               return
+       }
 
-               case false:
-                       device.BindClose()
+       // change state of device
 
-                       device.peers.mutex.Lock()
-                       defer device.peers.mutex.Unlock()
+       switch newIsUp {
+       case true:
+               if err := device.BindUpdate(); err != nil {
+                       device.isUp.Set(false)
+                       break
+               }
+               device.peers.mutex.Lock()
+               for _, peer := range device.peers.keyMap {
+                       peer.Start()
+               }
+               device.peers.mutex.Unlock()
 
-                       for _, peer := range device.peers.keyMap {
-                               println("stopping peer")
-                               peer.Stop()
-                       }
+       case false:
+               device.BindClose()
+               device.peers.mutex.Lock()
+               for _, peer := range device.peers.keyMap {
+                       peer.Stop()
                }
+               device.peers.mutex.Unlock()
+       }
 
-               // update state variables
+       // update state variables
 
-               device.state.current = newIsUp
-               device.state.changing.Set(false)
-       }()
+       device.state.current = newIsUp
+       device.state.changing.Set(false)
+       device.state.mutex.Unlock()
 
        // check for state change in the mean time
 
diff --git a/peer.go b/peer.go
index dc048118c8b64f9937914a8fce143ccde57a9836..d8bb2bf90ff133f49d62d82edf1b7211d02e946b 100644 (file)
--- a/peer.go
+++ b/peer.go
@@ -4,7 +4,6 @@ import (
        "encoding/base64"
        "errors"
        "fmt"
-       "github.com/sasha-s/go-deadlock"
        "sync"
        "time"
 )
@@ -15,7 +14,7 @@ const (
 
 type Peer struct {
        isRunning                   AtomicBool
-       mutex                       deadlock.RWMutex
+       mutex                       sync.RWMutex
        persistentKeepaliveInterval uint64
        keyPairs                    KeyPairs
        handshake                   Handshake
@@ -29,7 +28,7 @@ type Peer struct {
        }
 
        time struct {
-               mutex         deadlock.RWMutex
+               mutex         sync.RWMutex
                lastSend      time.Time // last send message
                lastHandshake time.Time // last completed handshake
                nextKeepalive time.Time
@@ -66,7 +65,7 @@ type Peer struct {
        }
 
        routines struct {
-               mutex    deadlock.Mutex // held when stopping / starting routines
+               mutex    sync.Mutex     // held when stopping / starting routines
                starting sync.WaitGroup // routines pending start
                stopping sync.WaitGroup // routines pending stop
                stop     Signal         // size 0, stop all go-routines in peer