MCPcopy Create free account
hub / github.com/Monibuca/engine / Reduce

Method Reduce

util/ring-writer.go:80–103  ·  view source on GitHub ↗
(size int)

Source from the content-addressed store, hash-verified

78}
79
80func (rb *RingWriter[T, F]) Reduce(size int) {
81 p := rb.Unlink(size)
82 pSize := size
83 rb.Size -= size
84 // 遍历即将回收的节点,如果有读锁未释放,则丢弃,不回收该节点
85 for i := 0; i < size; i++ {
86 if !p.Value.IsDiscarded() && p.Value.StartWrite() { // 尝试加写锁,成功则说明该节点可正常回收
87 p.Value.Reset()
88 p.Value.Ready()
89 rb.poolSize++
90 } else {
91 p.Value.Reset()
92 if pSize == 1 {
93 // last one,无法删除最后一个节点,直接返回即可(不回收)
94 return
95 }
96 p = p.Prev()
97 p.Unlink(1) // 丢弃该节点,不回收
98 pSize--
99 }
100 p = p.Next()
101 }
102 rb.recycle(p)
103}
104
105func (rb *RingWriter[T, F]) Dispose() {
106 if rb.disposeFlag.Add(-2) == -2 {

Callers 2

StepMethod · 0.95
narrowMethod · 0.80

Calls 8

recycleMethod · 0.95
UnlinkMethod · 0.80
PrevMethod · 0.80
IsDiscardedMethod · 0.65
StartWriteMethod · 0.65
ResetMethod · 0.65
ReadyMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected