Commit Graph

63 Commits

Author SHA1 Message Date
Abhinav Gupta
08f23f163e Generate atomic Value wrappers automatically
Rather than hand-writing wrappers around atomic.Value, generate them
automatically from the same template. The generator is at
internal/gen-valuewrapper. The generator correctly handles generating
wrapper structs for nillable types.
2020-05-12 11:30:18 -07:00
Abhinav Gupta
d9a13c26a5 Generate atomic integers automatically
Rather than hand-writing the atomic integers, generate them
automatically from the same template. The generator is at
internal/gen-atomicint.

To ensure these are never out of date, add another `make` target which
verifies that the working tree is left unchanged after regenerating
code.
2020-05-12 11:30:09 -07:00
Abhinav Gupta
530718eef1 ints: Pull types into independent files
In anticipation of automatically generating these definitions, pull the
definitions of the various integer types into their own files as well as
their tests.

This will make it easier to review the changes when each of these files
is generated independently and automatically.
2020-05-11 16:15:06 -07:00
Prashant Varanasi
1b900bfc8c Replace escaped strings with raw string literals (#71) 2020-05-11 14:48:55 -07:00
Abhinav Gupta
fb0c2ade64 string: Implement TextMarshaler, TextUnmarshaler (#70)
Since String holds textual information, instead of implementing
json.Marshaler and json.Unmarshaler, we should implement
encoding.TextMarshaler and encoding.TextUnmarshaler on String.

This makes it encodable and decodable using a variety of formats
including JSON, XML, YAML, and TOML.
2020-05-11 14:40:09 -07:00
Abhinav Gupta
7311447a2c tests: Use subtests for JSON (#69)
Change JSON marshaling and unmarshaling tests to use subtests for
cleaner separation in output as well as for easier visual scanning.
2020-05-11 11:21:02 -07:00
Daniel Malmer
fcb7ed1e69 Add JSON Marshal and Unmarshal (#68)
Support serializing and deserializing atomic objects to/from JSON using
the JSON representation of the underlying types. Without this,
marshaling returns `{}`.

Per discussion in #68, `atomic.Value` does not yet implement support
because there's an open question as to whether it should implement it
even if the underlying type doesn't support JSON marshaling/
unmarshaling.

Resolves #49
2020-05-10 07:17:21 -07:00
Abhinav Gupta
b2c105d12e Back to development 2020-02-24 13:58:47 -08:00
Abhinav Gupta
845920076a Preparing release v 1.6.0 (#66)
This releases v1.6.0.
v1.6.0
2020-02-24 13:57:07 -08:00
Abhinav Gupta
9cf2b0ab39 Drop dependency on golang.org/x/{tools,lint} (#65)
We use `golang.org/x/{tools,lint}` for dev-time tooling only. We don't
need to declare it as a library dependency. This causes issues like
https://github.com/uber-go/multierr/issues/35.

This change drops these depnedencies by renaming the tools.go so that
these are considered test dependencies only. `go mod vendor` does not
consider test dependencies.
2020-02-24 13:51:01 -08:00
Prashant Varanasi
60aeda6ff1 Back to development 2019-11-19 13:35:34 -08:00
Prashant Varanasi
40ae6a40a9 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.
v1.5.1
2019-11-19 13:33:40 -08:00
Abhinav Gupta
b99530f7f5 README: Fix legacy import path instructions (#60)
In migrating to Go modules, we had to decide between the import paths
github.com/uber-go/atomic and go.uber.org/atomic. We chose the latter.

As a result of this, users of the legacy import path would get an error
message similar to the following:

    github.com/uber-go/atomic: github.com/uber-go/atomic@v1.5.0: parsing go.mod:
    module declares its path as: go.uber.org/atomic
            but was required as: github.com/uber-go/atomic

We suggested that users of the legacy import path add the following to
their go.mod.

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

This is inaccurate and will result in the following error message:

    go.uber.org/atomic@v1.5.0 used for two different module paths
    (github.com/uber-go/atomic and go.uber.org/atomic)

This was not detected before because `go mod tidy` works fine with this
`replace` directive. It fails only when it gets to `go build`.

After digging into this more, per section 4.4 of the resolution section
of [How can I resolve "parsing go.mod: unexpected module path" (..)][1],
the correct method of resolving this is to downgrade the legacy import
path to a version prior to the use of Go modules.

  [1]: https://github.com/golang/go/wiki/Modules#how-can-i-resolve-parsing-gomod-unexpected-module-path-and-error-loading-module-requirements-errors-caused-by-a-mismatch-between-import-paths-vs-declared-module-identity

So the correct `replace` directive here would be,

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

This fix was verified both, locally and by @atibhav21 who first ran into
this.
2019-11-04 15:54:56 -08:00
Abhinav Gupta
fb77e1d737 Back to development 2019-10-29 15:14:36 -07:00
Abhinav Gupta
9dc4df04d0 Preparing release v1.5.0 (#58) v1.5.0 2019-10-29 15:13:04 -07:00
Abhinav Gupta
473b9563f0 Switch to Go modules (#56)
This switches atomic to Go modules. This has the effect of simplifying
the Makefile and the Travis build, as well as getting rid of the overly
complicated coverage script we copied here.

Tools dependencies (currently only golint) were added to the tools.go.

As a result of this change, we no longer support the non-vanity import path
github.com/uber-go/atomic. Users must use the vanity import path, or add a
`replace` directive.

Supersedes #40
2019-10-29 15:04:38 -07:00
Abhinav Gupta
187d219e0c Add a CHANGELOG (#57)
This adds a CHANGELOG.md to the project, retroactively filling it up
based on https://github.com/uber-go/atomic/releases.
2019-10-29 14:13:54 -07:00
Sergey Shepelev
ef0d20d85b Fix typo in make lint rule (#55) 2019-07-31 12:47:37 -07:00
Prashant Varanasi
df976f2515 Run lint on 1.12, remove pre-1.11 versions (#52)
Clean up the Makefile to use ./... instead of a packages variable.

Golint checks vendor when used with "./..." so use `go list ./...`.
This lint check was previously not even running (PKGS was undefined).
v1.4.0
2019-05-01 13:56:49 -07:00
Abhinav Gupta
5a6ca66254 README: Switch to travis-ci.com for badge (#51) 2019-04-29 13:45:39 -07:00
Prashant Varanasi
5328d69c76 Simplify lint version select, control via .travis.yml (#46)
This is similar to tchannel, see
https://github.com/uber/tchannel-go/pull/651

and
https://github.com/uber/tchannel-go/blob/dev/.travis.yml
2019-02-25 17:13:05 -08:00
William Banfield
8dc6146f75 switch hr to native markdown to render link (#43) 2018-10-18 14:50:23 -07:00
alexeypavlenko
bb9a8edc0f Introduce an atomic type-safe wrapper around error type. (#42) 2018-09-27 09:07:59 -07:00
Oleg Kovalov
ca68046243 Update Go versions on Travis (#41) 2018-08-05 21:53:14 -07:00
Nathan Jordan
1ea20fb1cb add atomic duration type (#37)
wrapper around existing `Int64` type for atomic operations on `time.Duration` values
v1.3.2
2018-05-01 10:38:09 -07:00
Prashant Varanasi
8474b86a5a Add standard library atomic operations to benchmark (#35)
Currently, we only benchmark our custom atomic types, but don't
benchmark the standard library types. Add benchmarks for ints and uints
that the standard library supports.
v1.3.1
2017-11-14 12:44:01 -08:00
Prashant Varanasi
54e9e20165 Add parallel benchmarks (#34)
Atomic operations tend to be fast when there's no contention but get a
lot slower with contention, so add tests which run the same stress test
in parallel.
2017-11-14 11:42:34 -08:00
Prashant Varanasi
0ee2c2d995 Concurrently modify same atomic in stress tests (#33)
Currently, the stress tests start multiple goroutines, but they all have
their own local atomic, so they are not concurrently modifying the same
values. Return a function which can be run concurrently to modify the
same atomic.
2017-11-14 10:36:59 -08:00
Prashant Varanasi
e81582a97d Revert "Optimization for String.Store("")" (#32)
This optimization causes data races since we're changing the value field
without using atomics. E.g., a caller who has multiple goroutines
calling `Set("1")` and `Set("")` will race on the access to `s.v` since
one goroutine is trying to read it while the other sets it, neither
using atomic operations.

This reverts commit 16b44f14f0.
2017-11-14 08:16:11 -08:00
Grayson Koonce
54f72d3243 Test Go 1.9 (#31) v1.3.0 2017-08-29 15:32:23 -07:00
Bill Fumerola
70bd1261d3 Use stress tests for benchmarks 2017-07-19 18:46:50 -04:00
Bill Fumerola
16b44f14f0 Optimization for String.Store("") 2017-07-19 18:44:22 -04:00
Prashant Varanasi
0506d69f55 Add .codecov with status checking for 100% coverage (#30) 2017-06-08 17:20:07 -07:00
Prashant Varanasi
3c3f2a99a1 Point coverage badge at codecov instead of coveralls 2017-06-08 16:17:25 -07:00
Prashant Varanasi
d245187332 Try codecov instead of coveralls (#28) 2017-06-08 16:14:49 -07:00
Bill Fumerola
908889c45e goreportcard badge 2017-05-24 19:49:27 -07:00
Bill Fumerola
a85b15eff9 Use our own Value for String 2017-05-09 14:47:25 -07:00
Prashant Varanasi
3f020e6d5d Add Bool.CAS for compare-and-swap semantics (#23) 2017-05-09 12:57:10 -07:00
Oleg Kovalov
1d7f075bbe Update Travis to run Go 1.7 and 1.8 versions (#22) 2017-04-30 10:40:09 -07:00
bill fumerola
4e336646b2 Shadow atomic.Value from sync/atomic (#19) v1.2.0 2017-04-10 19:30:53 -07:00
bill fumerola
1dcf4eb483 Update lint-worthy version list (#20) 2017-04-10 17:14:58 -07:00
Anton Tyurin
3b8db5e93c Implement Add/Sub for Float64 (#17)
Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
v1.1.0
2016-12-15 11:56:52 -08:00
Bill Fumerola
74ca5ec650 Add stress test for Float64 2016-12-14 13:12:48 -08:00
bill fumerola
14746df0c2 Merge pull request #16 from uber-go/refactor_stress
Refactor stress tests and wait for the results
2016-12-13 11:16:23 -08:00
Prashant Varanasi
9058d5b913 Refactor stress tests and wait for the results
Previously, we were not waiting for the spawned goroutines to end.
Refactor the logic to use a common runStress that runs some function
from multiple goroutines.
2016-12-13 11:10:34 -08:00
Prashant Varanasi
9e99152552 Fix Go tip errors with self-import (#14) 2016-10-27 09:36:08 -07:00
Prashant Varanasi
0ab99594f7 Use go.uber.org import path (#13) 2016-10-27 00:33:41 -07:00
Kunal Thakar
6c2817a9ef Atomic wrapper around float64 (#12) 2016-10-19 17:45:26 -07:00
Prashant Varanasi
0c9e689d64 Merge pull request #10 from uber-go/unexport
Use unexported field name instead of embedding
v1.0.0
2016-07-18 13:38:59 -07:00
Prashant Varanasi
e59e67d981 Use unexported field name instead of embedding
Unexported field name means the methods on different types look
more similar (e.g., &i.v instead of &i.int32 or &i.uint32).

For String, this is important since we don't want users to be
able to access the underlying atomic.Value
2016-07-18 12:50:08 -07:00