mirror of
https://github.com/pyihe/go-pkg.git
synced 2025-10-06 16:36:50 +08:00
18 lines
275 B
Go
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)))
|
|
}
|