storeSeqlockSection writes a data section guarded by the seqlock at seqOff: bump the counter odd, run write (which gets the section's data slice starting right after the 8-byte counter), bump it even.
(data []byte, seqOff int, write func(buf []byte))
| 163 | // bump the counter odd, run write (which gets the section's data slice starting |
| 164 | // right after the 8-byte counter), bump it even. |
| 165 | func storeSeqlockSection(data []byte, seqOff int, write func(buf []byte)) error { |
| 166 | seqPtr := (*uint64)(unsafe.Pointer(&data[seqOff])) |
| 167 | for range maxReadTries { |
| 168 | seq := atomic.LoadUint64(seqPtr) |
| 169 | if seq&1 != 0 { |
| 170 | time.Sleep(time.Microsecond) |
| 171 | continue |
| 172 | } |
| 173 | seq = (seq &^ 1) + 1 |
| 174 | atomic.StoreUint64(seqPtr, seq) |
| 175 | seq++ |
| 176 | write(data[seqOff+8:]) |
| 177 | if seq == 0 { |
| 178 | seq = 2 |
| 179 | } |
| 180 | atomic.StoreUint64(seqPtr, seq) |
| 181 | return nil |
| 182 | } |
| 183 | return fmt.Errorf("seqlock contention after %d tries", maxReadTries) |
| 184 | } |
| 185 | |
| 186 | // loadSeqlockSection returns a fresh copy of dataLen bytes from the section |
| 187 | // guarded by the seqlock at seqOff, retrying if a write raced the read. |
no outgoing calls
no test coverage detected
searching dependent graphs…