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

@CLAassistant

CLAassistant commented Oct 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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
@AdamMagued
AdamMagued force-pushed the add-uint8-uint16-support branch from 69d263c to 03df7b1 Compare October 14, 2026 12:03
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