mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: rename IncRef() to TryIncRef() to better reflect its behavior
PiperOrigin-RevId: 572084130
This commit is contained in:
committed by
gVisor bot
parent
1e5df83edf
commit
1a680b825b
@@ -2196,7 +2196,7 @@ func (e *endpoint) acquireOutgoingPrimaryAddressRLocked(remoteAddr tcpip.Address
|
||||
// Return the most preferred address that can have its reference count
|
||||
// incremented.
|
||||
for _, c := range cs {
|
||||
if c.addressEndpoint.IncRef() {
|
||||
if c.addressEndpoint.TryIncRef() {
|
||||
return c.addressEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ func (a *AddressableEndpointState) acquirePrimaryAddressRLocked(remoteAddr tcpip
|
||||
bestLen = stateLen
|
||||
}
|
||||
}
|
||||
if best != nil && best.IncRef() {
|
||||
if best != nil && best.TryIncRef() {
|
||||
return best
|
||||
}
|
||||
}
|
||||
@@ -492,7 +492,7 @@ func (a *AddressableEndpointState) acquirePrimaryAddressRLocked(remoteAddr tcpip
|
||||
}
|
||||
|
||||
if !ep.Deprecated() {
|
||||
if ep.IncRef() {
|
||||
if ep.TryIncRef() {
|
||||
// ep is not deprecated, so return it immediately.
|
||||
//
|
||||
// If we kept track of a deprecated endpoint, decrement its reference
|
||||
@@ -509,7 +509,7 @@ func (a *AddressableEndpointState) acquirePrimaryAddressRLocked(remoteAddr tcpip
|
||||
|
||||
return ep
|
||||
}
|
||||
} else if deprecatedEndpoint == nil && ep.IncRef() {
|
||||
} else if deprecatedEndpoint == nil && ep.TryIncRef() {
|
||||
// We prefer an endpoint that is not deprecated, but we keep track of
|
||||
// ep in case a doesn't have any non-deprecated endpoints.
|
||||
//
|
||||
@@ -541,7 +541,7 @@ func (a *AddressableEndpointState) AcquireAssignedAddressOrMatching(localAddr tc
|
||||
return nil
|
||||
}
|
||||
|
||||
if !addrState.IncRef() {
|
||||
if !addrState.TryIncRef() {
|
||||
panic(fmt.Sprintf("failed to increase the reference count for address = %s", addrState.addr))
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ func (a *AddressableEndpointState) AcquireAssignedAddressOrMatching(localAddr tc
|
||||
|
||||
if f != nil {
|
||||
for _, addrState := range a.endpoints {
|
||||
if addrState.IsAssigned(allowTemp) && f(addrState) && addrState.IncRef() {
|
||||
if addrState.IsAssigned(allowTemp) && f(addrState) && addrState.TryIncRef() {
|
||||
return addrState
|
||||
}
|
||||
}
|
||||
@@ -805,7 +805,7 @@ func (a *addressState) IsAssigned(allowExpired bool) bool {
|
||||
}
|
||||
|
||||
// IncRef implements AddressEndpoint.
|
||||
func (a *addressState) IncRef() bool {
|
||||
func (a *addressState) TryIncRef() bool {
|
||||
return a.refs.TryIncRef()
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestAddressDispatcherExpiredToAssigned(t *testing.T) {
|
||||
t.Fatalf("s.AddAndAcquirePermanentAddress(%s, {}): %s", addr, err)
|
||||
}
|
||||
defer ep.DecRef()
|
||||
if !ep.IncRef() {
|
||||
if !ep.TryIncRef() {
|
||||
t.Fatalf("failed to increase ref count of address endpoint")
|
||||
}
|
||||
|
||||
|
||||
@@ -534,11 +534,11 @@ type AssignableAddressEndpoint interface {
|
||||
// to its NetworkEndpoint.
|
||||
IsAssigned(allowExpired bool) bool
|
||||
|
||||
// IncRef increments this endpoint's reference count.
|
||||
// TryIncRef tries to increment this endpoint's reference count.
|
||||
//
|
||||
// Returns true if it was successfully incremented. If it returns false, then
|
||||
// the endpoint is considered expired and should no longer be used.
|
||||
IncRef() bool
|
||||
TryIncRef() bool
|
||||
|
||||
// DecRef decrements this endpoint's reference count.
|
||||
DecRef()
|
||||
|
||||
@@ -537,7 +537,7 @@ func (r *Route) Acquire() {
|
||||
// +checklocksread:r.mu
|
||||
func (r *Route) acquireLocked() {
|
||||
if ep := r.localAddressEndpoint; ep != nil {
|
||||
if !ep.IncRef() {
|
||||
if !ep.TryIncRef() {
|
||||
panic(fmt.Sprintf("failed to increment reference count for local address endpoint = %s", r.LocalAddress()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user