Skip to content

Commit

Permalink
Merge pull request #148 from cloudwego/release/v0.2.4
Browse files Browse the repository at this point in the history
chore: release v0.2.4
  • Loading branch information
Hchenn authored May 20, 2022
2 parents 659bc6c + 71d9142 commit 4a19aee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion connection_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ func (c *connection) initFinalizer() {
c.stop(flushing)
// stop the finalizing state to prevent conn.fill function to be performed
c.stop(finalizing)
freeop(c.operator)
c.netFD.Close()
c.closeBuffer()
freeop(c.operator)
return nil
})
}
Expand Down
9 changes: 4 additions & 5 deletions nocopy_linkbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ func (b *LinkBuffer) recalLen(delta int) (length int) {
// Nodes with size <= 0 are marked as readonly, which means the node.buf is not allocated by this mcache.
func newLinkBufferNode(size int) *linkBufferNode {
var node = linkedPool.Get().(*linkBufferNode)
// reset node offset
node.off, node.malloc, node.refer, node.readonly = 0, 0, 1, false
if size <= 0 {
node.readonly = true
return node
Expand Down Expand Up @@ -754,14 +756,11 @@ func (node *linkBufferNode) Release() (err error) {
}
// release self
if atomic.AddInt32(&node.refer, -1) == 0 {
node.off, node.malloc, node.refer, node.origin, node.next = 0, 0, 1, nil, nil
// readonly nodes cannot recycle node.buf, other node.buf are recycled to mcache.
if node.readonly {
node.readonly = false
} else {
if !node.readonly {
free(node.buf)
}
node.buf = nil
node.buf, node.origin, node.next = nil, nil, nil
linkedPool.Put(node)
}
return nil
Expand Down
9 changes: 4 additions & 5 deletions nocopy_linkbuffer_race.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ func (b *LinkBuffer) recalLen(delta int) (length int) {
// Nodes with size <= 0 are marked as readonly, which means the node.buf is not allocated by this mcache.
func newLinkBufferNode(size int) *linkBufferNode {
var node = linkedPool.Get().(*linkBufferNode)
// reset node offset
node.off, node.malloc, node.refer, node.readonly = 0, 0, 1, false
if size <= 0 {
node.readonly = true
return node
Expand Down Expand Up @@ -803,14 +805,11 @@ func (node *linkBufferNode) Release() (err error) {
}
// release self
if atomic.AddInt32(&node.refer, -1) == 0 {
node.off, node.malloc, node.refer, node.origin, node.next = 0, 0, 1, nil, nil
// readonly nodes cannot recycle node.buf, other node.buf are recycled to mcache.
if node.readonly {
node.readonly = false
} else {
if !node.readonly {
free(node.buf)
}
node.buf = nil
node.buf, node.origin, node.next = nil, nil, nil
linkedPool.Put(node)
}
return nil
Expand Down
1 change: 0 additions & 1 deletion nocopy_linkbuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ func TestLinkBufferRefer(t *testing.T) {
MustNil(t, err)
MustTrue(t, rbuf.head != node1)
MustTrue(t, buf.head == node2)
Equal(t, node1.Len(), 0)

err = buf.Release()
MustNil(t, err)
Expand Down

0 comments on commit 4a19aee

Please sign in to comment.