diff options
author | Josh Bleecher Snyder <josh@tailscale.com> | 2020-12-10 11:25:08 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-07 14:49:44 +0100 |
commit | c9e4a859ae8cdd7046a467afe8b50c5364c2cfc7 (patch) | |
tree | 933a4c47443a72e8431ec5155775f93a84ac2314 /device/device.go | |
parent | 3591acba76d30ea7986ff5828cefcd7d8f705be2 (diff) |
device: remove starting waitgroups
In each case, the starting waitgroup did nothing but ensure
that the goroutine has launched.
Nothing downstream depends on the order in which goroutines launch,
and if the Go runtime scheduler is so broken that goroutines
don't get launched reasonably promptly, we have much deeper problems.
Given all that, simplify the code.
Passed a race-enabled stress test 25,000 times without failure.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/device.go')
-rw-r--r-- | device/device.go | 11 |
1 files changed, 0 insertions, 11 deletions
diff --git a/device/device.go b/device/device.go index c440679..9e2d001 100644 --- a/device/device.go +++ b/device/device.go @@ -27,7 +27,6 @@ type Device struct { // synchronized resources (locks acquired in order) state struct { - starting sync.WaitGroup stopping sync.WaitGroup sync.Mutex changing AtomicBool @@ -35,7 +34,6 @@ type Device struct { } net struct { - starting sync.WaitGroup stopping sync.WaitGroup sync.RWMutex bind conn.Bind // bind interface @@ -297,23 +295,18 @@ func NewDevice(tunDevice tun.Device, logger *Logger) *Device { // start workers cpus := runtime.NumCPU() - device.state.starting.Wait() device.state.stopping.Wait() for i := 0; i < cpus; i += 1 { - device.state.starting.Add(3) device.state.stopping.Add(3) go device.RoutineEncryption() go device.RoutineDecryption() go device.RoutineHandshake() } - device.state.starting.Add(2) device.state.stopping.Add(2) go device.RoutineReadFromTUN() go device.RoutineTUNEventReader() - device.state.starting.Wait() - return device } @@ -370,8 +363,6 @@ func (device *Device) Close() { return } - device.state.starting.Wait() - device.log.Info.Println("Device closing") device.state.changing.Set(true) device.state.Lock() @@ -527,11 +518,9 @@ func (device *Device) BindUpdate() error { // start receiving routines - device.net.starting.Add(2) device.net.stopping.Add(2) go device.RoutineReceiveIncoming(ipv4.Version, netc.bind) go device.RoutineReceiveIncoming(ipv6.Version, netc.bind) - device.net.starting.Wait() device.log.Debug.Println("UDP bind has been updated") } |