• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Jul-2021-

abool-3c25f2fe7cd0/H28-Jun-2016-338254

.gitignoreH A D20-Jul-2021266 2519

LICENSEH A D20-Jul-20211.1 KiB2217

README.mdH A D20-Jul-20211.4 KiB5035

bool.goH A D20-Jul-20211.4 KiB6439

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