Skip to content
/ abool Public
forked from tevino/abool

💡 Atomic Boolean library for cleaner Go code, optimized for performance yet simple to use.

License

Notifications You must be signed in to change notification settings

jdvjdv82/abool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ABool 💡

Atomic Boolean package for Go, optimized for performance yet simple to use.

Designed for cleaner code.

Usage

package abool


cond := abool.New()     // default to false

cond.Set()              // Sets to true
cond.IsSet()            // Returns true
cond.UnSet()            // Sets to false
cond.IsNotSet()         // Returns true
cond.SetTo(any)         // Sets to whatever you want
cond.SetToIf(old, new)  // Sets to `new` only if the Boolean matches the `old`, returns whether succeeded


// embedding
type Foo struct {
    cond *abool.AtomicBool  // always use pointer to avoid copy
}

Benchmark:

  • Go 1.6.2
  • OS X 10.11.4
  • Intel CPU (to be specified)
# Read
BenchmarkMutexRead-48                   656360493                8.691 ns/op           0 B/op          0 allocs/op
BenchmarkAtomicValueRead-48             1000000000               0.2631 ns/op          0 B/op          0 allocs/op
BenchmarkAtomicBoolRead-48              1000000000               0.2515 ns/op          0 B/op          0 allocs/op

# Write
BenchmarkMutexWrite-48                  693644023                8.755 ns/op           0 B/op          0 allocs/op
BenchmarkAtomicValueWrite-48            980383506                5.572 ns/op           0 B/op          0 allocs/op
BenchmarkAtomicBoolWrite-48             1000000000               4.468 ns/op           0 B/op          0 allocs/op

# CAS
BenchmarkMutexCAS-48                    316539304               18.47 ns/op            0 B/op          0 allocs/op
BenchmarkAtomicBoolCAS-48               1000000000               4.179 ns/op           0 B/op          0 allocs/op




Special thanks to contributors

About

💡 Atomic Boolean library for cleaner Go code, optimized for performance yet simple to use.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%