119 Commits

Author SHA1 Message Date
mleku
359bf54565 changing urls again
Some checks failed
FOSSA Analysis / build (push) Has been cancelled
Go / build (1.17.x) (push) Has been cancelled
Go / build (1.18.x) (push) Has been cancelled
Go / build (1.19.x, true) (push) Has been cancelled
v1.11.2
2023-11-27 13:47:17 +00:00
mleku
53d29ac909 changing urls for new repo
Some checks failed
FOSSA Analysis / build (push) Has been cancelled
Go / build (1.17.x) (push) Has been cancelled
Go / build (1.18.x) (push) Has been cancelled
Go / build (1.19.x, true) (push) Has been cancelled
v1.11.1
2023-11-24 10:40:32 +00:00
Gabriel Cipriano
b1c4565f21 replace deprecated function CAS in examples (#138)
Update example_test.go and README.md replacing deprecated func
2023-07-14 11:17:35 -07:00
Manjari Akella
8af810e0b0 Back to development (#137) 2023-05-03 14:32:19 -07:00
Manjari Akella
f129756e76 Preparing release v1.11.0 (#136) 2023-05-03 14:20:34 -07:00
Sung Yoon Whang
544d6aa5c2 Minimize permissions to CI workflows (#133)
Set only read permission on CI workflows since they don't need write access.

Fixes #132.
2023-03-20 09:52:44 -07:00
Prashant Varanasi
1505d282ac Fix Swap and CompareAndSwap for Value wrappers (#130)
* Regenerate code to update copyright end year to 2023

* Test behaviour of default values initialized in different ways

This adds repro tests for #126 and #129

* Fix Swap and CompareAndSwap for Value wrappers

Fixes #126, #129

All atomic types can be used without initialization, e.g., `var v
<AtomicType>`. This works fine for integer types as the initialized
value of 0 matches the default value for the user-facing type.  However,
for Value wrappers, they are initialized to `nil`, which is a value that
can't be set (triggers a panic) so the default value for the user-facing
type is forced to be stored as a different value. This leads to multiple
possible values representing the default user-facing type.

E.g., an `atomic.String` with value `""` may be represented by the
underlying atomic as either `nil`, or `""`. This causes issues when we
don't handle the `nil` value correctly, causing to panics in `Swap` and
incorrectly not swapping values in `CompareAndSwap`.

This change fixes the above issues by:
 * Requiring `pack` and `unpack` function in gen-atomicwrapper as the
   only place we weren't supplying them was for `String`, and the
   branching adds unnecessary complexity, especially with added `nil`
   handling.
 * Extending `CompareAndSwap` for `Value` wrappers to try an additional
   `CompareAndSwap(nil, <new>)` only if the original `CompareAndSwap`
   fails and the old value is the zero value.
2023-02-06 01:17:57 -08:00
josephinedotlee
78a3b8ec6c Implement String method for pointers (#122)
* Implement String method for pointers

By implementing this method ourselves using atomic
loading and fmt.Sprint, we can avoid possible unguarded
accesses to the embedded pointer if someone attempts to
fmt.Print the atomic.Pointer
.

* Use Pointer.Load, not wrapped.Load

Co-authored-by: Abhinav Gupta <abg@uber.com>
2022-09-20 15:23:16 -07:00
Abhinav Gupta
159e329dd8 chore(gen-*): Move templates into external files (#121)
This moves the templates used by gen-atomicint and gen-atomicwrapper
into external files embedded into the corresponding gen binary with
go:embed.
2022-09-06 10:26:51 -07:00
Abhinav Gupta
9680036303 Prepare release v1.10.0 (#118)
Some checks failed
FOSSA Analysis / build (push) Has been cancelled
Go / build (1.17.x) (push) Has been cancelled
Go / build (1.18.x) (push) Has been cancelled
Go / build (1.19.x, true) (push) Has been cancelled
Prepare a new release with the following changes:
https://github.com/uber-go/atomic/compare/v1.9.0...2ab21d86f69c08c9cab261d3bf4d97954e673c9c
v1.10.0
2022-08-11 16:31:55 -07:00
Abhinav Gupta
2ab21d86f6 Add Pointer[T] (#116)
Adds a Pointer[T] type that provide the same functionality as
Go 1.19's `sync/atomic.Pointer[T]` in both, Go 1.18 and 1.19.

In Go 1.19, this uses the standard library's implementation,
and in 1.18 our own custom implementation based on UnsafePointer.
For Go 1.17, even though it's now unsupported, this is a no-op.

Refs GO-1572
Resolves #115
2022-08-09 16:56:14 -07:00
Abhinav Gupta
d144bb6cd7 Drop use of deprecated ioutil package (#117) 2022-08-09 14:30:10 -07:00
eNV25
d4bbbc828d Add CompareAndSwap and Swap, Deprecate CAS (#111)
Adds CompareAndSwap and Swap methods to String, Error, and Value,
implemented by making use of Value.CompareAndSwap and Value.Swap
added in Go 1.17.

Following that, add CompareAndSwap to all other types with "CAS" methods
and deprecate CAS in favor of CompareAndSwap, since that's the convention
the standard library chose for these in Go 1.19.
2022-08-06 11:12:19 -07:00
eNV25
01497d22b0 nocmp_test: fix spelling in comment (#114) 2022-08-05 22:46:25 -07:00
Abhinav Gupta
d15bdada1c ci: Test with Go 1.19 (#113)
Test against Go 1.19 and lint only for the latest version.
Update to latest staticcheck to work with 1.19.
2022-08-05 09:53:49 -07:00
eNV25
edb52d7eaa Value: place nocmp zero-sized field first (#109) 2022-08-05 09:21:10 -07:00
Abhinav Gupta
122c956c5a all: Update copyright notices (#112)
This will reduce noise in other PRs.
2022-08-05 09:19:12 -07:00
eNV25
976602f5dc all: go fmt ./... with go1.19 (#110) 2022-08-05 09:14:45 -07:00
whoisix
f9aa9cb571 Provide atomic type for float32 (#107) 2022-05-06 12:12:31 -07:00
Abhinav Gupta
adc54d9a09 CI: Test against Go 1.17 and 1.18 (#104) 2022-03-15 14:38:35 -07:00
Abhinav Gupta
3504dfaa1f Release v1.9.0 (#101)
Some checks failed
FOSSA Analysis / build (push) Has been cancelled
Go / build (1.15.x) (push) Has been cancelled
Go / build (1.16.x, true) (push) Has been cancelled
This release v1.9.0 of go.uber.org/atomic. The list of changes in this releases
is [v1.8.0...997edd6][1].

[1]: https://github.com/uber-go/atomic/compare/v1.8.0...997edd6

In updating the changelog, I moved the reference links around so that each
reference link was in its own section rather than piled at the bottom of the
file where it gets pretty ungainly.
v1.9.0
2021-07-15 10:19:10 -07:00
Abhinav Gupta
7f3beef9c0 Prepare release v1.9.0
This prepares release v1.9.0 of go.uber.org/atomic.
2021-07-15 10:14:20 -07:00
Abhinav Gupta
b9b54c3ce2 CHANGELOG: Move reference links to each section
The list of reference links at the bottom gets pretty ungainly. Move
references to the section for each version.

This should have no effect on the actual Markdown output.
2021-07-15 10:13:10 -07:00
Prashant Varanasi
997edd622f uintptr test: Fix overflow on architectures with 32-bit pointers (#100)
Fixes #99

The current uintptr test assumes that pointers are 64-bit, so the test
fails to compile on architectures with 32-bit pointers. Instead, cast
-1 to uintptr, which matches math.MaxUint64 on 64-bit architectures, and
math.MaxUint32 on 32-bit architectures.

Verified by using GOARCH=386
2021-07-09 09:22:17 -07:00
Sung Yoon Whang
557b938325 Add atomic.Time (#98)
* Add atomic.Time

* fix the arg variable name in the generated code from x to t

* fix build err

* lint

* add changelog entry

* add more tests to show we preserve the whole time.Time struct

* removing add/sub/round

* code review feedback
2021-06-22 00:36:49 -07:00
Sung Yoon Whang
6a01446a63 Fix lint error on float64_ext.go (#97) 2021-06-17 15:09:53 -07:00
Prashant Varanasi
d8a8972198 Improve argument/return names for better docs (#96)
This change is a renaming with no functional changes.

It includes the following renames:
 * `val` for arguments that replace the atomic value (e.g., `Store`).
 * `delta` for arguments that offset the atomic value (e.g., `Add`).
 * `old`, `new` for arguments to `CAS`.
 * `old` named return from `Swap`.
 * `swapped` for named return from `CAS`.

This also matches the names used in the stdlib atomic interface:
https://golang.org/pkg/sync/atomic/
2021-06-11 10:20:12 -07:00
Prashant Varanasi
df5a5c3c08 Add Swap for Float64 (#94)
Float64 wraps a Uint64, and since Uint64 supports Swap, Float64 can also
support Swap. Enable the Swap method in the generated code, and add
tests.

This also adds a note for why String doesn't support Swap (though it
will be possible after Go 1.17+).
2021-06-11 08:23:41 -07:00
Prashant Varanasi
38b6e7fa63 Add note on Float64.CAS matching of NaN (#95)
NaN != NaN when using Go's inbuilt operator, but the same is not true
when used with Float64.CAS. Add a note calling this out.

Changing this would be a behaviour change (requires a major version
bump), and is likely unsafe as it could lead to typical CAS loops
blocking forever.

To add the note, we copy the generated CAS method and extend the
documentation as the generator does not support per-method
customizations on the doc comments.
2021-06-11 08:16:20 -07:00
Abhinav Gupta
0c8e1ec21d Release v1.8.0 (#93)
Some checks failed
FOSSA Analysis / build (push) Has been cancelled
Go / build (1.15.x) (push) Has been cancelled
Go / build (1.16.x, true) (push) Has been cancelled
Release v1.8.0 of atomic with support for atomic wrappers for uintptr
and unsafe.Pointer.
v1.8.0
2021-06-09 09:13:58 -07:00
tison
05e06dc209 Add uintptr, unsafe.Pointer atomics (#90)
Add support for atomic `uintptr` and `unsafe.Pointer` types.

For `unsafe.Pointer`, name the atomic variant `atomic.UnsafePointer` to
maintain the "unsafe" portion of the name in usage.

Resolves #88
2021-06-08 17:44:58 -07:00
Abhinav Gupta
2a929df6c0 generate: Use year range for license (#92)
The generators gen-atomicint and gen-atomicwrapper hard-coded the year
into the licenses of the generated files.

Update to generate year ranges for the licenses, starting at 2020, going
to whatever today's year is.
2021-06-08 11:27:37 -07:00
tison
5422f5b703 PR template: Drop CLA instructions (#91)
CLAassistant will verify and have the user sign the CLA if needed so we
don't need the outdated link in the contribution guide.
2021-06-08 08:40:19 -07:00
Abhinav Gupta
19a675e6b3 fossa: Run separately, only on push (#87)
FOSSA analysis currently blocks CI on pull requests because they are
denied access to secrets.

Run FOSSA as a separate job only when we push to a branch of the
project.
2021-05-25 15:16:02 -07:00
Manjari Akella
9c6ac71468 Integrate FOSSA (#86)
Add a FOSSA check to the build steps.

Resolves: GO-468
2021-05-25 12:08:50 -07:00
Dmitriy Shirchenko
3db2fee91a Switch to GitHub Actions from Travis. (#85)
Use GitHub Actions because we're deprecating use of Travis for our OSS
projects.

This change ran into some issues with the `generatenodirty` check so
we changed it to print `git status`. We ran into an issue where
`go mod download` was changing the go.sum and `go mod tidy` was alone.

As a workaround for this, the CI job doesn't `go mod download` by
default; we'll let the actual `test` or `build` commands do that.
2021-05-10 15:29:57 -07:00
Abhinav Gupta
9c79392530 nomcmp/test: Only set HOME (#84)
After some more digging into #83, the issue was actually lack of HOME.
We need to specify GOPATH and GOCACHE because we haven't specified a
HOME.

Given the setup,

```
cd $(mktemp -d)
echo "module example.com/demo" > go.mod
echo "package demo" > demo.go
eval $(gimme 1.16rc1)
GO=$(which go)
```

If we run `go build` with an empty environment, it fails as expected.

```
$ env -i $GO build
missing $GOPATH
```

Setting HOME gives it a good default place for GOPATH, GOCACHE, and
friends.

```
$ env -i HOME=$(pwd)/home $GO build  # succeeds
```
2021-02-02 14:19:09 -08:00
Abhinav Gupta
d17779fa59 nocmp/test: Test with Go modules (#83)
The nocmp integration test creates a temporary directory with a copy of
nocmp.go and a Go file that should not compile if our implementation of
nocmp is correct.

This worked fine without a GOPATH set previously, but with Go 1.16, it
seems that we need to have the GOPATH environment variable set (ref
https://github.com/golang/go/commit/cdbd4d49d8b).

Change the nocmp integration test to rely on Go modules for the test.
We can point GOPATH to an arbitrary temporary directory because we don't
rely on anything in it.

Fixes #82
2021-02-02 10:07:29 -08:00
Abhinav Gupta
12f27ba263 Release v1.7.0 (#80)
Release v1.7.0 of atomic. This includes a couple additional features as
well as the correctness change introduced in (#74).
v1.7.0
2020-09-14 09:04:36 -07:00
Abhinav Gupta
e315f0689d Add staticcheck and fix issues (#79)
This adds `staticcheck` to `make lint` and fixes issues found by it.
2020-09-11 11:27:26 -07:00
Abhinav Gupta
cd88893c2f stress_test: Fix i64/std case
The i64/std case was testing with 32-bit integers instead of 64-bit
integers.
2020-09-11 11:24:56 -07:00
Abhinav Gupta
f64e592f7f staticcheck: Fix unused fields
The embedded `nocmp` field and other similar fields are unused in tests
and the rest of our code.

We can get the effect of `nocmp` without embedding the fields by using
`_ nocmp` as a field.
2020-09-11 11:24:56 -07:00
Abhinav Gupta
746c19c0c5 TestNocmpSize: Test with correct struct
`staticcheck` caught the following issue.

    nocmp_test.go:84:7: type y is unused (U1000)

Test was intended to evaluate the size of the new `type y` but due to a
typo, we were testing with `x`.
2020-09-11 11:24:56 -07:00
Abhinav Gupta
5066fe7a9d make/lint: Add staticcheck
Include staticcheck among the linters we run during `make lint`.
2020-09-11 11:24:56 -07:00
Abhinav Gupta
501585e5ef tools: Move to a submodule (#78)
Renaming tools.go to tools_test.go isn't enough. These constraints are
still carried over to consumers. Renaming only drops them from
`go mod vendor`.

This moves tools dependencies to a `tools` submodule which we will never
publish.

Ref uber-go/multierr#38
2020-09-11 11:24:19 -07:00
Abhinav Gupta
7ccfa79b88 Generate all atomics automatically (#77)
`gen-valuewrapper` is specialized to generating type-safe atomic
wrappers around `atomic.Value`. This limitation is unnecessary. Given
functions to convert an exposed type to the underlying type (referred to
as "packing" here) and back ("unpacking"), we can generate wrappers
around any backing atomic type.

This generalizes `valuewrapper` into an `atomicwrapper` implementing
said functionality, and adding opt-in support for generating CAS, Swap,
and JSON methods.

With this, we can automatically generate bool, float64, and
time.Duration atomic wrappers on top of Uint32, Uint64, and Int64
respectively, as well as their core functionality.
2020-05-15 15:49:02 -07:00
Abhinav Gupta
b3957f7343 duration: Generate with gen-atomicwrapper
Generate atomic.Duration with gen-valuewrapper by wrapping atomic.Int64.
Use type casts to int64 and time.Duration as pack and unpack.
2020-05-15 15:47:25 -07:00
Abhinav Gupta
e63519f6ea float64: Generate with gen-atomicwrapper
Generate atomic.Float64 with gen-valuewrapper by wrapping atomic.Uint64,
using math.Float64bits and math.Float64frombits to pack and unpack
float64 to uint64.
2020-05-15 15:47:25 -07:00
Abhinav Gupta
f455d48e53 bool: Generate with gen-valuewrapper
Generate atomic.Bool with gen-valuewrapper by wrapping atomic.Uint32.
CAS, Swap, and JSON implementations are generated automatically.
2020-05-15 15:47:25 -07:00
Abhinav Gupta
af220de512 Separate files for each atomic type
As in #73, separate each atomic type into its own file to ease review of
transition to generated code.

After moving every atomic to its own file, the atomic.go file serves
only as documentation, so rename it to doc.go.
2020-05-15 15:47:25 -07:00