mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-05 02:00:30 +08:00
fix: count items
This commit is contained in:
7
item.go
7
item.go
@@ -138,12 +138,7 @@ func (b *Item[T]) destroybystat(stat status) {
|
|||||||
var v T
|
var v T
|
||||||
b.val = v
|
b.val = v
|
||||||
}
|
}
|
||||||
if stat.hasignored() { // ignore put
|
b.pool.put(b, stat.hasignored())
|
||||||
runtime.SetFinalizer(b, nil)
|
|
||||||
b.cfg = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b.pool.put(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManualDestroy item and put it back to pool.
|
// ManualDestroy item and put it back to pool.
|
||||||
|
|||||||
16
pool.go
16
pool.go
@@ -106,7 +106,7 @@ func (pool *Pool[T]) newempty() *Item[T] {
|
|||||||
return item.setautodestroy()
|
return item.setautodestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *Pool[T]) put(item *Item[T]) {
|
func (pool *Pool[T]) put(item *Item[T], hasignore bool) {
|
||||||
runtime.SetFinalizer(item, nil)
|
runtime.SetFinalizer(item, nil)
|
||||||
|
|
||||||
item.cfg = nil
|
item.cfg = nil
|
||||||
@@ -118,15 +118,17 @@ func (pool *Pool[T]) put(item *Item[T]) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exist := pool.dupmap.LoadOrStore(item, struct{}{})
|
if !hasignore {
|
||||||
if exist {
|
_, exist := pool.dupmap.LoadOrStore(item, struct{}{})
|
||||||
panic("duplicated put")
|
if exist {
|
||||||
|
panic("duplicated put")
|
||||||
|
}
|
||||||
|
|
||||||
|
pool.pool.Put(item)
|
||||||
|
pool.incin()
|
||||||
}
|
}
|
||||||
|
|
||||||
pool.pool.Put(item)
|
|
||||||
|
|
||||||
pool.decout()
|
pool.decout()
|
||||||
pool.incin()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New call this to generate an item.
|
// New call this to generate an item.
|
||||||
|
|||||||
Reference in New Issue
Block a user