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

Function StoreFBClockData

fbclock/shmem_notlinux.go:123–142  ·  view source on GitHub ↗

StoreFBClockData writes fbclock data to shared memory via mmap

(fd uintptr, d Data)

Source from the content-addressed store, hash-verified

121
122// StoreFBClockData writes fbclock data to shared memory via mmap
123func StoreFBClockData(fd uintptr, d Data) error {
124 data, err := unix.Mmap(int(fd), 0, shmDataSize, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED)
125 if err != nil {
126 return fmt.Errorf("mmap failed: %w", err)
127 }
128 defer func() { _ = unix.Munmap(data) }()
129
130 buf := (*[40]byte)(unsafe.Pointer(&data[8]))
131 binary.LittleEndian.PutUint64(buf[0:8], uint64(d.IngressTimeNS))
132 binary.LittleEndian.PutUint32(buf[8:12], Uint64ToUint32(d.ErrorBoundNS))
133 binary.LittleEndian.PutUint32(buf[12:16], FloatAsUint32(d.HoldoverMultiplierNS))
134 binary.LittleEndian.PutUint64(buf[16:24], d.SmearingStartS)
135 binary.LittleEndian.PutUint64(buf[24:32], d.SmearingEndS)
136 binary.LittleEndian.PutUint32(buf[32:36], uint32(d.UTCOffsetPreS))
137 binary.LittleEndian.PutUint32(buf[36:40], uint32(d.UTCOffsetPostS))
138
139 crc := clockDataCRC(buf)
140 atomic.StoreUint64((*uint64)(unsafe.Pointer(&data[0])), crc)
141 return nil
142}
143
144// ReadFBClockData reads Data from mmaped fbclock shared memory
145func ReadFBClockData(shmp unsafe.Pointer) (*Data, error) {

Callers

nothing calls this directly

Calls 3

Uint64ToUint32Function · 0.85
FloatAsUint32Function · 0.85
clockDataCRCFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…