cmd/tailscale: remove redundant locking

There are no more concurrent accesses to the prefs variable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/3/head
Elias Naur 4 years ago
parent 42a327e5e5
commit ad92c8d81f

@ -146,11 +146,7 @@ func (a *App) runBackend() error {
alarmChan = timer.C alarmChan = timer.C
} }
} }
var prefs struct { var prefs *ipn.Prefs
once sync.Once
mu sync.Mutex
prefs *ipn.Prefs
}
notifications := make(chan ipn.Notify, 1) notifications := make(chan ipn.Notify, 1)
startErr := make(chan error) startErr := make(chan error)
// Start from a goroutine to avoid deadlock when Start // Start from a goroutine to avoid deadlock when Start
@ -181,17 +177,13 @@ func (a *App) runBackend() error {
configErrs <- b.updateTUN(service, cfg) configErrs <- b.updateTUN(service, cfg)
case n := <-notifications: case n := <-notifications:
if p := n.Prefs; p != nil { if p := n.Prefs; p != nil {
prefs.mu.Lock() first := prefs == nil
prefs.prefs = p.Clone() prefs = p.Clone()
prefs.mu.Unlock() if first {
a.setPrefs(prefs.prefs) prefs.Hostname = a.hostname()
prefs.once.Do(func() { b.backend.SetPrefs(prefs)
prefs.mu.Lock() }
prefs.prefs.Hostname = a.hostname() a.setPrefs(prefs)
p := prefs.prefs
prefs.mu.Unlock()
b.backend.SetPrefs(p)
})
} }
if s := n.State; s != nil { if s := n.State; s != nil {
oldState := state.State oldState := state.State
@ -245,11 +237,8 @@ func (a *App) runBackend() error {
case LogoutEvent: case LogoutEvent:
go b.backend.Logout() go b.backend.Logout()
case ConnectEvent: case ConnectEvent:
prefs.mu.Lock() prefs.WantRunning = e.Enable
p := prefs.prefs go b.backend.SetPrefs(prefs)
prefs.mu.Unlock()
p.WantRunning = e.Enable
go b.backend.SetPrefs(p)
} }
case s := <-onConnect: case s := <-onConnect:
jni.Do(a.jvm, func(env jni.Env) error { jni.Do(a.jvm, func(env jni.Env) error {

Loading…
Cancel
Save