MCPcopy Create free account
hub / github.com/facebook/time / storeSeqlockSection

Function storeSeqlockSection

fbclock/shmem_notlinux.go:165–184  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

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.
165func 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.

Callers 2

StoreFBClockDataV2Function · 0.85
StoreFBClockDataRealtimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…