10 MaxWaitInProgress = time.Millisecond * 100
11 CheckDelayInProgress = time.Microsecond * 10
14 type sharedHeaderBase struct {
22 type statSegSharedHeader struct {
27 func (h *statSegSharedHeader) legacyVersion() bool {
28 // older VPP (<=19.04) did not have version in stat segment header
29 // we try to provide fallback support by skipping it in header
30 if h.version > maxVersion && h.inProgress > 1 && h.epoch == 0 {
36 func statSegHeader(b []byte) (header statSegSharedHeader) {
37 h := (*statSegSharedHeader)(unsafe.Pointer(&b[0]))
38 header.version = atomic.LoadUint64(&h.version)
39 header.epoch = atomic.LoadInt64(&h.epoch)
40 header.inProgress = atomic.LoadInt64(&h.inProgress)
41 header.directoryOffset = atomic.LoadInt64(&h.directoryOffset)
42 header.errorOffset = atomic.LoadInt64(&h.errorOffset)
43 header.statsOffset = atomic.LoadInt64(&h.statsOffset)
47 func statSegHeaderLegacy(b []byte) (header statSegSharedHeader) {
48 h := (*sharedHeaderBase)(unsafe.Pointer(&b[0]))
50 header.epoch = atomic.LoadInt64(&h.epoch)
51 header.inProgress = atomic.LoadInt64(&h.inProgress)
52 header.directoryOffset = atomic.LoadInt64(&h.directoryOffset)
53 header.errorOffset = atomic.LoadInt64(&h.errorOffset)
54 header.statsOffset = atomic.LoadInt64(&h.statsOffset)
58 type statSegAccess struct {
62 func (c *statSegment) accessStart() statSegAccess {
65 epoch, inprog := c.getEpoch()
67 if time.Since(t) > MaxWaitInProgress {
68 return statSegAccess{}
70 time.Sleep(CheckDelayInProgress)
72 epoch, inprog = c.getEpoch()
79 func (c *statSegment) accessEnd(acc *statSegAccess) bool {
80 epoch, inprog := c.getEpoch()
81 if acc.epoch != epoch || inprog {
87 type vecHeader struct {
92 func vectorLen(v unsafe.Pointer) uint64 {
93 vec := *(*vecHeader)(unsafe.Pointer(uintptr(v) - unsafe.Sizeof(uintptr(0))))
98 func statSegPointer(p unsafe.Pointer, offset uintptr) unsafe.Pointer {
99 return unsafe.Pointer(uintptr(p) + offset)