Skip to content

Add atomic.Uint8 and atomic.Uint16 support - #220

Open
AdamMagued wants to merge 1 commit into
uber-go:masterfrom
AdamMagued:add-uint8-uint16-support
Open

AdamMagued wants to merge 1 commit into
uber-go:masterfrom
AdamMagued:add-uint8-uint16-support

Conversation

@AdamMagued

Copy link
Copy Markdown

Summary

Adds atomic.Uint8 and atomic.Uint16 types to go.uber.org/atomic, providing type-safe atomic operations on 8-bit and 16-bit unsigned integers.

Because standard library sync/atomic only provides primitives for 32-bit and 64-bit words, Uint8 and Uint16 are backed by Uint32 with compare-and-swap (CAS) loops for arithmetic modifications, ensuring accurate unsigned overflow and wrap-around semantics.

Changes

  • Add Uint8 and Uint16 atomic wrappers with generation directives using gen-atomicwrapper.
  • Provide full API parity matching existing integer atomics:
    • NewUint8, NewUint16
    • Load, Store, Swap
    • CompareAndSwap, CAS
    • Add, Sub, Inc, Dec (via lock-free CAS loop)
    • String
    • MarshalJSON, UnmarshalJSON
    • MarshalText, UnmarshalText
  • Update non-comparability tests in nocmp_test.go to cover Uint8 and Uint16.
  • Add concurrent stress test cases in stress_test.go.
  • Add comprehensive unit tests in uint8_test.go and uint16_test.go verifying 100% statement coverage.

Fixes #123

Add Uint8 and Uint16 atomic wrappers backed by Uint32 with compare-and-swap loops for arithmetic operations. Provide complete API compatibility including New, Load, Store, Swap, CAS, CompareAndSwap, Add, Sub, Inc, Dec, String, JSON marshaling, and Text marshaling.

Fixes uber-go#123
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Adam Magued seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atomic.Uint8 atomic.Uint16 support not found

2 participants