Files
go-pkg/syncpkg/counter.go
2022-03-04 17:24:23 +08:00

18 lines
275 B
Go

package syncpkg
import "sync/atomic"
type AtomicInt int32
func (ai *AtomicInt) Inc() {
atomic.AddInt32((*int32)(ai), 1)
}
func (ai *AtomicInt) Dec() {
atomic.AddInt32((*int32)(ai), -1)
}
func (ai *AtomicInt) Value() int {
return int(atomic.LoadInt32((*int32)(ai)))
}