Skip to content

Commit bca4708

Browse files
committed
Improve the comments
1 parent 78b760c commit bca4708

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pulsar/internal/buffer.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ func (p *bufferPoolImpl) GetBuffer(initSize int) Buffer {
118118

119119
func (p *bufferPoolImpl) Put(buf Buffer) {
120120
if b, ok := buf.(*buffer); ok {
121-
// Get the callback before putting back to the pool because it might be reset
121+
// Get the callback before putting back to the pool because it might be reset after the
122+
// buffer is returned to the pool and reused in GetBuffer.
122123
cb := b.releaseCallback
123124
p.Pool.Put(b)
124125
if cb != nil {
@@ -133,8 +134,12 @@ type buffer struct {
133134
readerIdx uint32
134135
writerIdx uint32
135136

136-
refCnt atomic.Int64
137-
pool BuffersPool
137+
refCnt atomic.Int64
138+
pool BuffersPool
139+
140+
// releaseCallback is an optional function that is called when the buffer is released back to the pool.
141+
// It allows custom cleanup or notification logic to be executed after the buffer is returned.
142+
// The callback is invoked in bufferPoolImpl.Put, after the buffer is put back into the pool.
138143
releaseCallback func()
139144
}
140145

0 commit comments

Comments
 (0)