Refer holds a reference count at the same time as Next, and releases the real buffer after Release. The node obtained by Refer is read-only.
(n int)
| 907 | // Refer holds a reference count at the same time as Next, and releases the real buffer after Release. |
| 908 | // The node obtained by Refer is read-only. |
| 909 | func (node *linkBufferNode) Refer(n int) (p *linkBufferNode) { |
| 910 | p = newLinkBufferNode(0) |
| 911 | p.buf = node.Next(n) |
| 912 | |
| 913 | if node.origin != nil { |
| 914 | p.origin = node.origin |
| 915 | } else { |
| 916 | p.origin = node |
| 917 | } |
| 918 | atomic.AddInt32(&p.origin.refer, 1) |
| 919 | return p |
| 920 | } |
| 921 | |
| 922 | // Release consists of two parts: |
| 923 | // 1. reduce the reference count of itself and origin. |
no test coverage detected