-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
18 changed files
with
252 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.