Skip to content

Instantly share code, notes, and snippets.

@rueian
Created February 4, 2022 09:25
Show Gist options
  • Save rueian/93aa872bf531f42f53ee35af5f07d349 to your computer and use it in GitHub Desktop.
Save rueian/93aa872bf531f42f53ee35af5f07d349 to your computer and use it in GitHub Desktop.
func (r *ring) EnqueueRequest(req request) response {
s := &r.slots[atomic.AddUint64(&r.write, 1)&1023]
for atomic.CompareAndSwapUint32(&s.mark, 0, 1) {
runtime.Gosched()
}
s.req = req
atomic.StoreUint32(&s.mark, 2)
return <-s.ch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment