connectioned: Change nested lock name to only have a single nested lock.

Now there's the unnamed one, and "higherID" which is the lock for the
endpoint that has a higher ID.

The lock dependency should consistently be "lower ID" -> "higher ID".

PiperOrigin-RevId: 491716600
This commit is contained in:
Etienne Perot
2022-11-29 13:06:57 -08:00
committed by gVisor bot
parent b112db0675
commit 1ceee8c310
2 changed files with 8 additions and 9 deletions
+1 -2
View File
@@ -22,8 +22,7 @@ declare_mutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
nested_lock_names = [
"e",
"ce",
"higherID",
],
package = "transport",
prefix = "endpoint",
@@ -288,27 +288,27 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
// Do a dance to safely acquire locks on both endpoints.
if e.id < ce.ID() {
e.Lock()
ce.NestedLock(endpointLockCe)
ce.NestedLock(endpointLockHigherid)
} else {
ce.Lock()
e.NestedLock(endpointLockE)
e.NestedLock(endpointLockHigherid)
}
// Check connecting state.
if ce.Connected() {
e.NestedUnlock(endpointLockE)
e.NestedUnlock(endpointLockHigherid)
ce.Unlock()
return syserr.ErrAlreadyConnected
}
if ce.ListeningLocked() {
e.NestedUnlock(endpointLockE)
e.NestedUnlock(endpointLockHigherid)
ce.Unlock()
return syserr.ErrInvalidEndpointState
}
// Check bound state.
if !e.ListeningLocked() {
e.NestedUnlock(endpointLockE)
e.NestedUnlock(endpointLockHigherid)
ce.Unlock()
return syserr.ErrConnectionRefused
}
@@ -359,7 +359,7 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
}
// Notify can deadlock if we are holding these locks.
e.NestedUnlock(endpointLockE)
e.NestedUnlock(endpointLockHigherid)
ce.Unlock()
// Notify on both ends.
@@ -369,7 +369,7 @@ func (e *connectionedEndpoint) BidirectionalConnect(ctx context.Context, ce Conn
return nil
default:
// Busy; return EAGAIN per spec.
e.NestedUnlock(endpointLockE)
e.NestedUnlock(endpointLockHigherid)
ce.Unlock()
ne.Close(ctx)
return syserr.ErrTryAgain