Skip to content

Commit

Permalink
Generate all atomics automatically (#77)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
abhinav committed May 15, 2020
2 parents ddc304d + b3957f7 commit 7ccfa79
Show file tree
Hide file tree
Showing 22 changed files with 1,066 additions and 629 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ export GOBIN ?= $(shell pwd)/bin

GOLINT = $(GOBIN)/golint
GEN_ATOMICINT = $(GOBIN)/gen-atomicint
GEN_VALUEWRAPPER = $(GOBIN)/gen-valuewrapper
GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper

GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print)

# Also update ignore section in .codecov.yml.
COVER_IGNORE_PKGS = \
go.uber.org/atomic/internal/gen-atomicint \
go.uber.org/atomic/internal/gen-valuewrapper
go.uber.org/atomic/internal/gen-atomicwrapper

.PHONY: build
build:
Expand All @@ -29,8 +29,8 @@ gofmt:
$(GOLINT):
go install golang.org/x/lint/golint

$(GEN_VALUEWRAPPER): $(wildcard ./internal/gen-valuewrapper/*)
go build -o $@ ./internal/gen-valuewrapper
$(GEN_ATOMICWRAPPER): $(wildcard ./internal/gen-atomicwrapper/*)
go build -o $@ ./internal/gen-atomicwrapper

$(GEN_ATOMICINT): $(wildcard ./internal/gen-atomicint/*)
go build -o $@ ./internal/gen-atomicint
Expand All @@ -54,7 +54,7 @@ cover:
go tool cover -html=cover.out -o cover.html

.PHONY: generate
generate: $(GEN_ATOMICINT) $(GEN_VALUEWRAPPER)
generate: $(GEN_ATOMICINT) $(GEN_ATOMICWRAPPER)
go generate ./...

.PHONY: generatenodirty
Expand Down
238 changes: 0 additions & 238 deletions atomic.go

This file was deleted.

Loading

0 comments on commit 7ccfa79

Please sign in to comment.