zatomic.go 369 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
21
22
23
24
25
26
27
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)))
}

func (i *Int) Load() int {
	return int(i.v.Load())
}

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