代码拉取完成,页面将自动刷新
package fastqueue
import "runtime"
const (
SpinMask = 1024*16 - 1 // arbitrary; we'll want to experiment with different values
)
type DefaultWriter struct {
written *Cursor // the ring buffer has been written up to this sequence
upstream Barrier // all of the readers have advanced up to this sequence
capacity int64
previous int64
gate int64
}
func NewWriter(written *Cursor, upstream Barrier, capacity int64) *DefaultWriter {
return &DefaultWriter{
upstream: upstream,
written: written,
capacity: capacity,
previous: defaultCursorValue,
gate: defaultCursorValue,
}
}
func (this *DefaultWriter) Reserve(count int64) int64 {
if count <= 0 {
panic(ErrMinimumReservationSize)
}
this.previous += count
for spin := int64(0); this.previous-this.capacity > this.gate; spin++ {
if spin&SpinMask == 0 {
runtime.Gosched() // LockSupport.parkNanos(1L); http://bit.ly/1xiDINZ
}
this.gate = this.upstream.Load()
}
return this.previous
}
func (this *DefaultWriter) Commit(_, upper int64) {
this.written.Store(upper)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。