Skip to content

Commit 405703d

Browse files
committed
atomicx: Add Inc/Dec
1 parent b0215d0 commit 405703d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/atomicx/atomicx.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ type Sum struct {
4545
f [2]atomic.Uint64
4646
}
4747

48+
func (x *Sum) Inc() {
49+
x.i.Add(1)
50+
}
51+
52+
func (x *Sum) Dec() {
53+
x.i.Add(^uint64(0))
54+
}
55+
4856
func (x *Sum) AddUint64(val uint64) {
4957
if val == 0 {
5058
return
@@ -57,6 +65,11 @@ func (x *Sum) Add(val float64) {
5765
return
5866
}
5967

68+
if val == 1 {
69+
x.Inc()
70+
return
71+
}
72+
6073
// if we're less than 1, we must be a float
6174
if val >= 1 {
6275
// Fast path to first check if the value is actually a whole number in

0 commit comments

Comments
 (0)