MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / SetIfMax

Method SetIfMax

base/util.go:1247–1258  ·  view source on GitHub ↗

SetIfMax sets the value of the atomic int to the given value if the given value is greater than the current value.

(value int64)

Source from the content-addressed store, hash-verified

1245
1246// SetIfMax sets the value of the atomic int to the given value if the given value is greater than the current value.
1247func (ai *AtomicInt) SetIfMax(value int64) {
1248 for {
1249 cur := atomic.LoadInt64(&ai.val)
1250 if cur >= value {
1251 return
1252 }
1253
1254 if atomic.CompareAndSwapInt64(&ai.val, cur, value) {
1255 return
1256 }
1257 }
1258}
1259
1260// Add adds the given value to the atomic int.
1261func (ai *AtomicInt) Add(value int64) {

Callers 2

TestSetIfMaxFunction · 0.45
updateStatsMethod · 0.45

Calls

no outgoing calls

Tested by 1

TestSetIfMaxFunction · 0.36