mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-10 17:20:39 +08:00
add missing done checks in ForChild methods
This commit is contained in:
parent
a42700a439
commit
35f25a934f
44
scope.go
44
scope.go
@ -394,6 +394,10 @@ func (s *ResourceScope) AddStreamForChild(incount, outcount int) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return ErrResourceScopeClosed
|
||||
}
|
||||
|
||||
return s.rc.addStream(incount, outcount)
|
||||
}
|
||||
|
||||
@ -401,6 +405,10 @@ func (s *ResourceScope) RemoveStream(dir network.Direction) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return
|
||||
}
|
||||
|
||||
var incount, outcount int
|
||||
if dir == network.DirInbound {
|
||||
incount = 1
|
||||
@ -417,6 +425,11 @@ func (s *ResourceScope) RemoveStream(dir network.Direction) {
|
||||
func (s *ResourceScope) RemoveStreamForChild(incount, outcount int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return
|
||||
}
|
||||
|
||||
s.rc.removeStream(incount, outcount)
|
||||
}
|
||||
|
||||
@ -460,6 +473,10 @@ func (s *ResourceScope) AddConnForChild(incount, outcount int) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return ErrResourceScopeClosed
|
||||
}
|
||||
|
||||
return s.rc.addConn(incount, outcount)
|
||||
}
|
||||
|
||||
@ -467,6 +484,10 @@ func (s *ResourceScope) RemoveConn(dir network.Direction) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return
|
||||
}
|
||||
|
||||
var incount, outcount int
|
||||
if dir == network.DirInbound {
|
||||
incount = 1
|
||||
@ -483,6 +504,11 @@ func (s *ResourceScope) RemoveConn(dir network.Direction) {
|
||||
func (s *ResourceScope) RemoveConnForChild(incount, outcount int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return
|
||||
}
|
||||
|
||||
s.rc.removeConn(incount, outcount)
|
||||
}
|
||||
|
||||
@ -490,6 +516,10 @@ func (s *ResourceScope) AddFD(count int) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return ErrResourceScopeClosed
|
||||
}
|
||||
|
||||
if err := s.rc.addFD(count); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -515,6 +545,11 @@ func (s *ResourceScope) AddFD(count int) error {
|
||||
func (s *ResourceScope) AddFDForChild(count int) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return ErrResourceScopeClosed
|
||||
}
|
||||
|
||||
return s.rc.addFD(count)
|
||||
}
|
||||
|
||||
@ -522,6 +557,10 @@ func (s *ResourceScope) RemoveFD(count int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return
|
||||
}
|
||||
|
||||
s.rc.removeFD(count)
|
||||
for _, cst := range s.constraints {
|
||||
cst.RemoveFDForChild(count)
|
||||
@ -531,6 +570,11 @@ func (s *ResourceScope) RemoveFD(count int) {
|
||||
func (s *ResourceScope) RemoveFDForChild(count int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.done {
|
||||
return
|
||||
}
|
||||
|
||||
s.rc.removeFD(count)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user