zatomic.go 462 Bytes
Newer Older
Vladimir Barsukov's avatar
zgo  
Vladimir Barsukov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package zatomic

import "sync/atomic"

type Int struct {
	v *atomic.Int32
}

func New() *Int {
	return &Int{v: &atomic.Int32{}}
}

func (i *Int) Store(v int) {
	i.v.Store(int32(v))
}

func (i *Int) Add(delta int) int {
	return int(i.v.Add(int32(delta)))
}

Vladimir Barsukov's avatar
fix    
Vladimir Barsukov committed
21
22
23
24
25
26
27
28
func (i *Int) Inc() int {
	return i.Add(1)
}

func (i *Int) Dec() int {
	return i.Add(-1)
}

Vladimir Barsukov's avatar
zgo  
Vladimir Barsukov committed
29
30
31
32
33
34
35
func (i *Int) Load() int {
	return int(i.v.Load())
}

func (i *Int) LoadInverse() int {
	return i.Load() * -1
}