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.
()
| 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. |
| 51 | func (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. |