MCPcopy Create free account
hub / github.com/erpc/erpc / allocateUpdatedAtMs

Method allocateUpdatedAtMs

data/shared_state_variable.go:51–62  ·  view source on GitHub ↗

allocateUpdatedAtMs allocates a strictly-increasing UpdatedAt timestamp (unix ms) for a local update. It also stores the allocated value into updatedAtUnixMs, ensuring uniqueness even under concurrency.

()

Source from the content-addressed store, hash-verified

49// allocateUpdatedAtMs allocates a strictly-increasing UpdatedAt timestamp (unix ms) for a local update.
50// It also stores the allocated value into updatedAtUnixMs, ensuring uniqueness even under concurrency.
51func (v *baseSharedVariable) allocateUpdatedAtMs() int64 {
52 for {
53 current := v.updatedAtUnixMs.Load()
54 next := time.Now().UnixMilli()
55 if next <= current {
56 next = current + 1
57 }
58 if v.updatedAtUnixMs.CompareAndSwap(current, next) {
59 return next
60 }
61 }
62}
63
64// updateUpdatedAtMs atomically advances updatedAtUnixMs if newUpdatedAt is newer.
65// Returns true if updatedAtUnixMs was advanced.

Callers 4

processNewStateMethod · 0.80
processNewValueMethod · 0.80
markFreshAttemptMethod · 0.80

Calls 1

LoadMethod · 0.80

Tested by 1