Documentation
¶
Overview ¶
Package atomic implements atomic operations as methods on types so they can be used more easily.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool is an atomic boolean. It can be flipped from known states to newly expected states and queries. A Bool can be created as part of other structures. The zero value for a Bool is false. A Bool must not be copied after first use.
Example ¶
package main import ( "fmt" "github.com/nightlyone/atomic" ) // Service is a flaky service. type Service struct { health atomic.Bool } func main() { service := new(Service) isHealthy := service.health.Value() fmt.Printf("service is healthy? %t\n", isHealthy) }
Output: service is healthy? false
func (*Bool) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation on bool, which is the atomic equivalent of:
if *b == old { *b = new return true } return false
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 provides AddInt32, StoreInt32, LoadInt32 and CompareAndSwapInt32 from the package sync/atomic as convenient methods on a type. An Int32 can be created as part of other structures. The zero value for an Int32 is 0. An Int32 must not be copied after first use.
func (*Int32) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation on i32, which is the atomic equivalent of:
if *i32 == old { *i32 = new return true } return false
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 provides AddInt64, StoreInt64, LoadInt64 and CompareAndSwapInt64 from the package sync/atomic as convenient methods on a type. An Int64 can be created as part of other structures. The zero value for an Int64 is 0. An Int64 must not be copied after first use.
func (*Int64) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation on i64, which is the atomic equivalent of:
if *i64 == old { *i64 = new return true } return false
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 provides AddUint32, StoreUint32, LoadUint32 and CompareAndSwapUint32 from the package sync/atomic as convenient methods on a type. An Uint32 can be created as part of other structures. The zero value for an Uint32 is 0. An Uint32 must not be copied after first use.
func (*Uint32) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation on u32, which is the atomic equivalent of:
if *u32 == old { *u32 = new return true } return false
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 provides AddUint64, StoreUint64, LoadUint64 and CompareAndSwapUint64 from the package sync/atomic as convenient methods on a type. An Uint64 can be created as part of other structures. The zero value for an Uint64 is 0. An Uint64 must not be copied after first use.
func (*Uint64) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation on u64, which is the atomic equivalent of:
if *u64 == old { *u64 = new return true } return false
Notes ¶
Bugs ¶
The implementation just wraps sync/atomic from the Go standard library, so it suffers the same implementation limitations.