Skip to content

Commit

Permalink
feat: MallocAck drop the tail nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hchenn committed Apr 12, 2022
1 parent f9dccd0 commit ffcc7e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions nocopy_linkbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ func (b *LinkBuffer) MallocAck(n int) (err error) {
b.write = b.write.next
}
// discard the rest
for node := b.write.next; node != nil; node = node.next {
node.off, node.malloc, node.refer, node.buf = 0, 0, 1, node.buf[:0]
for b.write.next != nil {
node := b.write.next
b.write.next = node.next
node.Release()
}
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions nocopy_linkbuffer_race.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ func (b *LinkBuffer) MallocAck(n int) (err error) {
b.write = b.write.next
}
// discard the rest
for node := b.write.next; node != nil; node = node.next {
node.off, node.malloc, node.refer, node.buf = 0, 0, 1, node.buf[:0]
for b.write.next != nil {
node := b.write.next
b.write.next = node.next
node.Release()
}
return nil
}
Expand Down

0 comments on commit ffcc7e1

Please sign in to comment.