Modify Bool to only use 1 or 0, rater than last bit (#62)

Most methods of Bool currently rely on the last bit, but `CAS`
generates the int value to match `old` based on the user's input
and so it assumes the value is either `1` or `0`.

The only reason we relid on the last bit is that `Toggle` was
implemented using an atomic add. We can instead implement
`Toggle` using a loop around `CAS`.

Fixes #61.
3 files changed
tree: 0fb1896368f7af57a53ce718535479d829ddb4e5
  1. .github/
  2. .codecov.yml
  3. .gitignore
  4. .travis.yml
  5. atomic.go
  6. atomic_test.go
  7. CHANGELOG.md
  8. error.go
  9. error_test.go
  10. example_test.go
  11. go.mod
  12. go.sum
  13. LICENSE.txt
  14. Makefile
  15. README.md
  16. stress_test.go
  17. string.go
  18. string_test.go
  19. tools.go
README.md

atomic GoDoc Build Status Coverage Status Go Report Card

Simple wrappers for primitive types to enforce atomic access.

Installation

$ go get -u go.uber.org/atomic@v1

Legacy Import Path

As of v1.5.0, the import path go.uber.org/atomic is the only supported way of using this package. If you are using Go modules, this package will fail to compile with the legacy import path path github.com/uber-go/atomic.

We recommend migrating your code to the new import path but if you're unable to do so, or if your dependencies are still using the old import path, you will have to add a replace directive to your go.mod file downgrading the legacy import path to an older version.

replace github.com/uber-go/atomic => github.com/uber-go/atomic v1.4.0

You can do so automatically by running the following command.

$ go mod edit -replace github.com/uber-go/atomic=github.com/uber-go/atomic@v1.4.0

Usage

The standard library‘s sync/atomic is powerful, but it’s easy to forget which variables must be accessed atomically. go.uber.org/atomic preserves all the functionality of the standard library, but wraps the primitive types to provide a safer, more convenient API.

var atom atomic.Uint32
atom.Store(42)
atom.Sub(2)
atom.CAS(40, 11)

See the documentation for a complete API specification.

Development Status

Stable.


Released under the MIT License.