Release consists of two parts: 1. reduce the reference count of itself and origin. 2. recycle the buf when the reference count is 0.
()
| 923 | // 1. reduce the reference count of itself and origin. |
| 924 | // 2. recycle the buf when the reference count is 0. |
| 925 | func (node *linkBufferNode) Release() (err error) { |
| 926 | if node.origin != nil { |
| 927 | node.origin.Release() |
| 928 | } |
| 929 | // release self |
| 930 | if atomic.AddInt32(&node.refer, -1) == 0 { |
| 931 | // readonly nodes cannot recycle node.buf, other node.buf are recycled to mcache. |
| 932 | if node.reusable() { |
| 933 | free(node.buf) |
| 934 | } |
| 935 | node.buf, node.origin, node.next = nil, nil, nil |
| 936 | linkedPool.Put(node) |
| 937 | } |
| 938 | return nil |
| 939 | } |
| 940 | |
| 941 | func (node *linkBufferNode) getFlag(flag uint8) bool { |
| 942 | return node.mode&flag > 0 |