lib/model: Use a single lock (#9275)

I'm tired of the fmut/pmut shenanigans. This consolidates both under one
lock; I'm not convinced there are any significant performance
differences with this approach since we're literally just protecting map
juggling...

- The locking goes away when we were already under an appropriate fmut
lock.
- Where we had fmut.RLock()+pmut.Lock() it gets upgraded to an
fmut.Lock().
- Otherwise s/pmut/fmut/.

In order to avoid diff noise for an important change I did not do the
following cleanups, which will be filed in a PR after this one, if
accepted:

- Renaming fmut to just mut
- Renaming methods that refer to being "PRLocked" and stuff like that
- Removing the no longer relevant deadlock detector
- Comments referring to pmut and locking sequences...
This commit is contained in:
Jakob Borg
2023-12-11 21:26:23 +01:00
committed by GitHub
parent c53a1f210c
commit 6f1023665c
2 changed files with 48 additions and 71 deletions
+6 -6
View File
@@ -902,13 +902,13 @@ func TestIssue5063(t *testing.T) {
defer cleanupModel(m)
defer cancel()
m.pmut.Lock()
m.fmut.Lock()
for _, c := range m.connections {
conn := c.(*fakeConnection)
conn.CloseCalls(func(_ error) {})
defer m.Closed(c, errStopped) // to unblock deferred m.Stop()
}
m.pmut.Unlock()
m.fmut.Unlock()
wg := sync.WaitGroup{}
@@ -2973,7 +2973,7 @@ func TestConnCloseOnRestart(t *testing.T) {
ci := &protocolmocks.ConnectionInfo{}
ci.ConnectionIDReturns(srand.String(16))
m.AddConnection(protocol.NewConnection(device1, br, nw, testutil.NoopCloser{}, m, ci, protocol.CompressionNever, nil, m.keyGen), protocol.Hello{})
m.pmut.RLock()
m.fmut.RLock()
if len(m.closed) != 1 {
t.Fatalf("Expected just one conn (len(m.closed) == %v)", len(m.closed))
}
@@ -2981,7 +2981,7 @@ func TestConnCloseOnRestart(t *testing.T) {
for _, c := range m.closed {
closed = c
}
m.pmut.RUnlock()
m.fmut.RUnlock()
waiter, err := w.RemoveDevice(device1)
if err != nil {
@@ -3074,12 +3074,12 @@ func TestDevicePause(t *testing.T) {
sub := m.evLogger.Subscribe(events.DevicePaused)
defer sub.Unsubscribe()
m.pmut.RLock()
m.fmut.RLock()
var closed chan struct{}
for _, c := range m.closed {
closed = c
}
m.pmut.RUnlock()
m.fmut.RUnlock()
pauseDevice(t, m.cfg, device1, true)