mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-10 17:20:39 +08:00
embed resources to avoid pointer indirection
This commit is contained in:
parent
7429488edb
commit
a6f536861c
12
scope.go
12
scope.go
@ -32,7 +32,7 @@ type ResourceScope struct {
|
||||
done bool
|
||||
refCnt int
|
||||
|
||||
rc *resources
|
||||
rc resources
|
||||
owner *ResourceScope // set in transaction scopes, which define trees
|
||||
constraints []*ResourceScope // set in DAG scopes, it's the linearized parent set
|
||||
}
|
||||
@ -40,25 +40,19 @@ type ResourceScope struct {
|
||||
var _ network.ResourceScope = (*ResourceScope)(nil)
|
||||
var _ network.TransactionalScope = (*ResourceScope)(nil)
|
||||
|
||||
func newResources(limit Limit) *resources {
|
||||
return &resources{
|
||||
limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
func NewResourceScope(limit Limit, constraints []*ResourceScope) *ResourceScope {
|
||||
for _, cst := range constraints {
|
||||
cst.IncRef()
|
||||
}
|
||||
return &ResourceScope{
|
||||
rc: newResources(limit),
|
||||
rc: resources{limit: limit},
|
||||
constraints: constraints,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTxnResourceScope(owner *ResourceScope) *ResourceScope {
|
||||
return &ResourceScope{
|
||||
rc: newResources(owner.rc.limit),
|
||||
rc: resources{limit: owner.rc.limit},
|
||||
owner: owner,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user