Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 20-Jul-2021 | - | ||||
abool-3c25f2fe7cd0/ | H | 28-Jun-2016 | - | 338 | 254 | |
.gitignore | H A D | 20-Jul-2021 | 266 | 25 | 19 | |
LICENSE | H A D | 20-Jul-2021 | 1.1 KiB | 22 | 17 | |
README.md | H A D | 20-Jul-2021 | 1.4 KiB | 50 | 35 | |
bool.go | H A D | 20-Jul-2021 | 1.4 KiB | 64 | 39 |
README.md
1# ABool :bulb: 2[![Go Report Card](https://goreportcard.com/badge/github.com/tevino/abool)](https://goreportcard.com/report/github.com/tevino/abool) 3[![GoDoc](https://godoc.org/github.com/tevino/abool?status.svg)](https://godoc.org/github.com/tevino/abool) 4 5Atomic Boolean library for Golang, optimized for performance yet simple to use. 6 7Use this for cleaner code. 8 9## Usage 10 11```go 12import "github.com/tevino/abool" 13 14cond := abool.New() // default to false 15 16cond.Set() // Set to true 17cond.IsSet() // Returns true 18cond.UnSet() // Set to false 19cond.SetTo(true) // Set to whatever you want 20cond.SetToIf(false, true) // Set to true if it is false, returns false(not set) 21 22 23// embedding 24type Foo struct { 25 cond *abool.AtomicBool // always use pointer to avoid copy 26} 27``` 28 29## Benchmark: 30 31- Golang 1.6.2 32- OS X 10.11.4 33 34```shell 35# Read 36BenchmarkMutexRead-4 100000000 21.0 ns/op 37BenchmarkAtomicValueRead-4 200000000 6.30 ns/op 38BenchmarkAtomicBoolRead-4 300000000 4.21 ns/op # <--- This package 39 40# Write 41BenchmarkMutexWrite-4 100000000 21.6 ns/op 42BenchmarkAtomicValueWrite-4 30000000 43.4 ns/op 43BenchmarkAtomicBoolWrite-4 200000000 9.87 ns/op # <--- This package 44 45# CAS 46BenchmarkMutexCAS-4 30000000 44.9 ns/op 47BenchmarkAtomicBoolCAS-4 100000000 11.7 ns/op # <--- This package 48``` 49 50