aboutsummaryrefslogtreecommitdiff
path: root/src/sync/atomic
AgeCommit message (Collapse)Author
13 daysall: add export linknames for assembly symbols accessed from other packageCherry Mui
For Go symbols accessed from other package via linkname or assembly, we have an export linkname from the definition side. We currently don't always have the linkname directive for assembly functions, for which external accesses are allowed. We may want to tighten up the restriction. So add export linknames for the ones that are needed. Change-Id: If664634c81580edd49086d916024f23f86871092 Reviewed-on: https://go-review.googlesource.com/c/go/+/749981 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-11-12sync/atomic: amend comments for Value.{Swap,CompareAndSwap}Jes Cok
Related to CL 241661, CL 403094. Change-Id: I86877d9a013b05b1a97f9aa1333cd96ce98469cb GitHub-Last-Rev: 7fedca5848cb17730d4ccb586dc03cfcb1b83259 GitHub-Pull-Request: golang/go#76259 Reviewed-on: https://go-review.googlesource.com/c/go/+/719660 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-25sync/atomic: correct Uintptr.Or return docMichael Pratt
Uintptr.Or returns the old value, just like all of the other Or functions. This was a typo in the original CL 544455. Fixes #75607. Change-Id: I260959e7e32e51f1152b5271df6cc51adfa02a4d Reviewed-on: https://go-review.googlesource.com/c/go/+/706816 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2025-04-24sync/atomic: document that atomic types should not be copiedMateusz Poliwczak
Change-Id: I3c557d02cd676a389b5c5ea70ed92c8959041e3b GitHub-Last-Rev: 8732da19a64853834ca155cafc1d7b2967290c31 GitHub-Pull-Request: golang/go#63256 Reviewed-on: https://go-review.googlesource.com/c/go/+/531375 Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Sean Liao <sean@liao.dev>
2024-11-15sync/atomic: make intrinsics noescape except 64bits op on 32bits arch and ↵Jorropo
unsafe.Pointer Fixes #16241 I made 64 bits op on 32 bits arches still leak since it was kinda promised. The promised leaks were wider than this but I don't belive it's effect can be observed in an breaking maner without using unsafe the way it's currently setup. Change-Id: I66d8df47bfe49bce3efa64ac668a2a55f70733a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/462298 Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-06-21sync/atomic: correct result names for Or methodsAustin Clements
A few of the new Or methods of the atomic types use "new" as the name for the result value, but it actually returns the old value. Fix this by renaming the result values to "old". Updates #61395. Change-Id: Ib08db9964f5dfe91929f216d50ff0c9cc891ee49 Reviewed-on: https://go-review.googlesource.com/c/go/+/593855 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Austin Clements <austin@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
2024-06-07sync: include links to the Go memory model in package documentationRodrigo Orselli
The lack of links to https://go.dev/ref/mem in the sync package documentation makes it difficult to read for people who have no previous knowledge of that page. This PR includes the links where needed. Fixes #67891 Change-Id: I0e1344cc6d7b702f4cb2e55fe0fcee3eb089391a GitHub-Last-Rev: 427cf58aaeaae2e4b060248dd592e5fe8c6b7df4 GitHub-Pull-Request: golang/go#67892 Reviewed-on: https://go-review.googlesource.com/c/go/+/591395 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-17sync/atomic: public And/Or ops and race instrumentationMauri de Souza Meneguzzo
This CL implements the new sync/atomic AND and OR apis as well as their race counterparts. Fixes #61395 Change-Id: I294eefe4b3ac27bc4ed237edcbfa88a8c646d86f GitHub-Last-Rev: f174297007c7b81b1ff4a687ef23d955a3ffd4db GitHub-Pull-Request: golang/go#64331 Reviewed-on: https://go-review.googlesource.com/c/go/+/544455 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2024-03-25runtime: migrate internal/atomic to internal/runtimeAndy Pan
For #65355 Change-Id: I65dd090fb99de9b231af2112c5ccb0eb635db2be Reviewed-on: https://go-review.googlesource.com/c/go/+/560155 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ibrahim Bazoka <ibrahimbazoka729@gmail.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2024-02-26sync: add available godoc linkcui fliter
Change-Id: I9bc5fd29b0eec8ceadcfee2116de5e7524ef92c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/539617 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-05-10all: fix a lot of commentscui fliter
Fix comments, including duplicate is, wrong phrases and articles, misspellings, etc. Change-Id: I8bfea53b9b275e649757cc4bee6a8a026ed9c7a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/493035 Reviewed-by: Benny Siegert <bsiegert@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-03-25all: add a few links in package godocsDaniel Martí
I noticed the one in path/filepath while reading the docs, and the other ones were found via some quick grepping. Change-Id: I386f2f74ef816a6d18aa2f58ee6b64dbd0147c9e Reviewed-on: https://go-review.googlesource.com/c/go/+/478795 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-02-09runtime: fix signature for linked functionsAdin Scannell
These functions are linked using go:linkname, but do not match the original declarations. This change brings these in sync. Change-Id: I16651304c3dba2f9897c2c42e30555d2f7805c2a Reviewed-on: https://go-review.googlesource.com/c/go/+/466615 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com>
2023-01-09sync/atomic: fix the note of atomic.Storecsuzhang
Change-Id: Id485d0f1e06febe97d1a770bc26c138d9613a7dd GitHub-Last-Rev: e57dd3e1abb58031b3d8bec8beace1560faad397 GitHub-Pull-Request: golang/go#57679 Reviewed-on: https://go-review.googlesource.com/c/go/+/461076 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org>
2022-11-17sync/atomic: hint users of old API to use new type-based API insteadKeith Randall
Fixes #56495 Change-Id: Ib2f39273da68e3056688306aa0d5e274b5507bf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/449237 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-15sync/atomic: allow linked list of atomic pointers againRuss Cox
For #56603, CL 448275 added a _ [0]T field to atomic.Pointer, so that different kinds of atomic.Pointer are not convertible. Unfortunately, that breaks code like: type List struct { Next atomic.Pointer[List] } which should be valid, just as using Next *List is valid. Instead, we get: ./atomic_test.go:2533:6: invalid recursive type List ./atomic_test.go:2533:6: List refers to ./atomic_test.go:2534:13: "sync/atomic".Pointer refers to ./atomic_test.go:2533:6: List Fix by using _[0]*T instead. Change-Id: Icc4c83c691d35961d20cb14b824223d6c779ac5e Reviewed-on: https://go-review.googlesource.com/c/go/+/450655 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-11-07sync/atomic: disallow type conversions of atomic.Pointer[T]Mateusz Poliwczak
Fixes #56603 Change-Id: I6af9d80201025ae4028bfaa4a62e5de9ac0c501d GitHub-Last-Rev: e6ed5e14512e1221a3c6cb181406cf00eec07e99 GitHub-Pull-Request: golang/go#56604 Reviewed-on: https://go-review.googlesource.com/c/go/+/448275 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-29sync/atomic: rename "ifaceWords" to "efaceWords"hopehook
Rename "ifaceWords" to "efaceWords", since we are defining an empty interface. Change-Id: I7151fb730a081a800e6dd28bcba831787ee9d6a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/432815 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-19cmd/compile,sync: make accessing address of zero offset struct field inline ↵Cuong Manh Le
cost 0 Accessing the address of something often needs the same (or even less) number of instructions as accessing the content of the thing. That would help us rolling back the hack of CL 429766 to lower sync atomic types inline cost. Compiled objects size increase a bit: file before after Δ % addr2line 3729827 3733958 +4131 +0.111% api 5457224 5456267 -957 -0.018% asm 4806486 4808993 +2507 +0.052% buildid 2480271 2480562 +291 +0.012% cgo 4593496 4593947 +451 +0.010% compile 23906958 23910086 +3128 +0.013% cover 4680870 4681461 +591 +0.013% dist 3341333 3341692 +359 +0.011% doc 3879927 3880409 +482 +0.012% fix 3298081 3298979 +898 +0.027% link 6500098 6499873 -225 -0.003% nm 3654362 3656997 +2635 +0.072% objdump 4108300 4108671 +371 +0.009% pack 2255445 2256391 +946 +0.042% pprof 14364561 14379475 +14914 +0.104% test2json 2550942 2555333 +4391 +0.172% trace 13573199 13578409 +5210 +0.038% vet 7430923 7430094 -829 -0.011% total 114612303 114651597 +39294 +0.034% file before after Δ % archive/tar.a 905032 905560 +528 +0.058% archive/zip.a 853464 853916 +452 +0.053% cmd/asm/internal/lex.a 359388 367418 +8030 +2.234% cmd/compile/internal/importer.a 947206 947734 +528 +0.056% cmd/compile/internal/inline.a 563390 566828 +3438 +0.610% cmd/compile/internal/types2.a 5761990 5764274 +2284 +0.040% cmd/go/internal/cfg.a 234892 235342 +450 +0.192% cmd/go/internal/envcmd.a 257166 257694 +528 +0.205% cmd/go/internal/fix.a 93522 94052 +530 +0.567% cmd/go/internal/generate.a 201308 201838 +530 +0.263% cmd/go/internal/get.a 207862 208390 +528 +0.254% cmd/go/internal/imports.a 230266 230794 +528 +0.229% cmd/go/internal/list.a 385044 386632 +1588 +0.412% cmd/go/internal/load.a 1164508 1165566 +1058 +0.091% cmd/go/internal/modcmd.a 627582 629168 +1586 +0.253% cmd/go/internal/modfetch/codehost.a 1031962 1032490 +528 +0.051% cmd/go/internal/modfetch.a 1289294 1289822 +528 +0.041% cmd/go/internal/modget.a 674566 675624 +1058 +0.157% cmd/go/internal/modindex.a 935598 936576 +978 +0.105% cmd/go/internal/modload.a 2640784 2642058 +1274 +0.048% cmd/go/internal/par.a 135858 136476 +618 +0.455% cmd/go/internal/run.a 127158 127688 +530 +0.417% cmd/go/internal/search.a 242918 243446 +528 +0.217% cmd/go/internal/trace.a 113216 113188 -28 -0.025% cmd/go/internal/vcs.a 517280 517810 +530 +0.102% cmd/go/internal/work.a 2389522 2390580 +1058 +0.044% cmd/go/internal/workcmd.a 311118 311452 +334 +0.107% cmd/vendor/github.com/google/pprof/internal/driver.a 1714950 1715478 +528 +0.031% cmd/vendor/golang.org/x/mod/sumdb.a 453840 454290 +450 +0.099% cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags.a 326162 326610 +448 +0.137% cmd/vendor/golang.org/x/tools/go/analysis/internal/facts.a 302476 303006 +530 +0.175% cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl.a 366580 367030 +450 +0.123% cmd/vendor/golang.org/x/tools/go/analysis/passes/assign.a 129556 130006 +450 +0.347% cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic.a 133466 133916 +450 +0.337% cmd/vendor/golang.org/x/tools/go/analysis/passes/bools.a 193558 194006 +448 +0.231% cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag.a 177984 178434 +450 +0.253% cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall.a 221226 221674 +448 +0.203% cmd/vendor/golang.org/x/tools/go/analysis/passes/composite.a 168572 169022 +450 +0.267% cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock.a 227040 227490 +450 +0.198% cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow.a 204650 205098 +448 +0.219% cmd/vendor/golang.org/x/tools/go/analysis/passes/errorsas.a 138020 138468 +448 +0.325% cmd/vendor/golang.org/x/tools/go/analysis/passes/framepointer.a 119030 119480 +450 +0.378% cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse.a 165006 165454 +448 +0.272% cmd/vendor/golang.org/x/tools/go/analysis/passes/ifaceassert.a 180850 181300 +450 +0.249% cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect.a 103876 104326 +450 +0.433% cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil.a 116070 116516 +446 +0.384% cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure.a 153068 153518 +450 +0.294% cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel.a 244936 245384 +448 +0.183% cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc.a 135720 136168 +448 +0.330% cmd/vendor/golang.org/x/tools/go/analysis/passes/printf.a 527134 527584 +450 +0.085% cmd/vendor/golang.org/x/tools/go/analysis/passes/shift.a 172026 172476 +450 +0.262% cmd/vendor/golang.org/x/tools/go/analysis/passes/sigchanyzer.a 151690 152138 +448 +0.295% cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods.a 187494 187944 +450 +0.240% cmd/vendor/golang.org/x/tools/go/analysis/passes/stringintconv.a 164752 165200 +448 +0.272% cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag.a 200144 200594 +450 +0.225% cmd/vendor/golang.org/x/tools/go/analysis/passes/testinggoroutine.a 161146 161596 +450 +0.279% cmd/vendor/golang.org/x/tools/go/analysis/passes/tests.a 270252 270702 +450 +0.167% cmd/vendor/golang.org/x/tools/go/analysis/passes/unmarshal.a 130646 131094 +448 +0.343% cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable.a 182130 182580 +450 +0.247% cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr.a 153646 154094 +448 +0.292% cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult.a 179800 180248 +448 +0.249% cmd/vendor/golang.org/x/tools/go/analysis/unitchecker.a 303838 304286 +448 +0.147% cmd/vendor/golang.org/x/tools/go/analysis.a 217930 218380 +450 +0.206% cmd/vendor/golang.org/x/tools/go/ast/astutil.a 539428 539874 +446 +0.083% cmd/vendor/golang.org/x/tools/go/cfg.a 286820 287270 +450 +0.157% cmd/vendor/golang.org/x/tools/go/types/objectpath.a 236144 236674 +530 +0.224% cmd/vendor/golang.org/x/tools/go/types/typeutil.a 412728 413176 +448 +0.109% cmd/vendor/golang.org/x/tools/internal/analysisinternal.a 223256 223704 +448 +0.201% cmd/vendor/golang.org/x/tools/internal/typeparams.a 419498 419946 +448 +0.107% context.a 210000 209972 -28 -0.013% crypto/internal/boring/bcache.a 8652 8568 -84 -0.971% crypto/tls.a 3295282 3295202 -80 -0.002% database/sql.a 1365892 1365762 -130 -0.010% encoding/base64.a 131572 136228 +4656 +3.539% encoding/binary.a 452546 453076 +530 +0.117% encoding/gob.a 1690728 1691672 +944 +0.056% encoding/json.a 1198834 1199276 +442 +0.037% encoding/xml.a 1035784 1036314 +530 +0.051% expvar.a 285282 285678 +396 +0.139% go/ast.a 1175212 1175662 +450 +0.038% go/build.a 657802 658252 +450 +0.068% go/doc.a 808002 808452 +450 +0.056% go/format.a 101378 101824 +446 +0.440% go/importer.a 101816 102266 +450 +0.442% go/internal/gccgoimporter.a 593828 594358 +530 +0.089% go/internal/gcimporter.a 974178 974626 +448 +0.046% go/internal/srcimporter.a 196600 197050 +450 +0.229% go/parser.a 1152502 1152946 +444 +0.039% go/printer.a 910744 911194 +450 +0.049% go/token.a 299624 299768 +144 +0.048% go/types.a 5763222 5766118 +2896 +0.050% hash/crc32.a 128130 128098 -32 -0.025% internal/fuzz.a 1058644 1059174 +530 +0.050% internal/poll.a 660412 660382 -30 -0.005% internal/testenv.a 212792 213320 +528 +0.248% log/syslog.a 128718 128654 -64 -0.050% log.a 157330 157274 -56 -0.036% mime.a 383058 383588 +530 +0.138% net/http/httptest.a 430550 431000 +450 +0.105% net/http/pprof.a 306918 307448 +530 +0.173% net/http.a 7413852 7414074 +222 +0.003% net/internal/socktest.a 258934 258900 -34 -0.013% net/rpc/jsonrpc.a 173158 172962 -196 -0.113% net/rpc.a 634464 634914 +450 +0.071% net.a 3539574 3541348 +1774 +0.050% os.a 891416 891390 -26 -0.003% reflect.a 3956224 3956666 +442 +0.011% runtime/cgo.a 187406 187852 +446 +0.238% runtime/trace.a 85720 85616 -104 -0.121% runtime.a 9357520 9371302 +13782 +0.147% sync/atomic.a 232512 232376 -136 -0.058% sync.a 353112 355068 +1956 +0.554% syscall.a 1660308 1660222 -86 -0.005% testing.a 1399348 1399198 -150 -0.011% text/template.a 1384750 1384726 -24 -0.002% total 265209524 265294628 +85104 +0.032% Change-Id: I21114dcddeb4fc2c56e781ea2f6e732fe3da2b01 Reviewed-on: https://go-review.googlesource.com/c/go/+/431095 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-09-09sync/atomic: reduce inlining cost for atomic types methodsCuong Manh Le
The "&x.v" cost us 2 inline cost budget, causing extra inline cost for the caller. By taking the fact that "v" is laid out in memory as the first field of all atomic types, we can accessing it without addressing. Discovering why attempting to convert sync.RWMutex.readerCount to atomic type. RWMutex.RUnlock have the inline cost 75, with extra 7 inline cost from Int32.Add causing it not inlinable anymore. With this change, Int32.Add only has 5 inline cost budget, RWMutex can use it while still be inlinable. Change-Id: Iabe1d1bf53389b0b8b5f56b4611231b732fd9df5 Reviewed-on: https://go-review.googlesource.com/c/go/+/429766 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-09-06all: make sure *Pointer[T]'s methods are inlined as intendedCuong Manh Le
Updates #50860 Change-Id: I65bced707e50364b16edf4b087c541cf19bb1778 Reviewed-on: https://go-review.googlesource.com/c/go/+/428362 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-08-05sync/atomic: remove test64err in testRuss Cox
This check was for very old QEMU, added in 2011 in https://codereview.appspot.com/4313051/. It may be safe to delete now. Let's find out. In a separate CL for easy rollback. Change-Id: Ic99f8cf27ee348b8ffb1ef0ee36cc1c537dde722 Reviewed-on: https://go-review.googlesource.com/c/go/+/403978 Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-07sync/atomic: clarify that 8-byte alignment of variables is due to escapeWill Hawkins
For #53223. Change-Id: I79e9b920488581a4d850e4051ee0dd600b5bbcb1 Reviewed-on: https://go-review.googlesource.com/c/go/+/410102 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Austin Clements <austin@google.com>
2022-06-06runtime, sync, sync/atomic: document happens-before guaranteesRuss Cox
A few of these are copied from the memory model doc. Many are entirely new, following discussion on #47141. See https://research.swtch.com/gomm for background. The rule we are establishing is that each type that is meant to help synchronize a Go program should document its happens-before guarantees. For #50859. Change-Id: I947c40639b263abe67499fa74f68711a97873a39 Reviewed-on: https://go-review.googlesource.com/c/go/+/381316 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-06-03sync/atomic: note that alignment responsibility doesn't apply to typesMichael Pratt
For #50860. Change-Id: I8e117f00c5da230d0dc398aaed417fe5e64a5b22 Reviewed-on: https://go-review.googlesource.com/c/go/+/410127 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-05-19all: gofmt main repoRuss Cox
Excluding vendor and testdata. CL 384268 already reformatted most, but these slipped past. The struct in the doc comment in debug/dwarf/type.go was fixed up by hand to indent the first and last lines as well. For #51082. Change-Id: Iad020f83aafd671ff58238fe491907e85923d0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/407137 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-06sync/atomic: don't run 64-bit uintptr tests on 32-bit systemsIan Lance Taylor
The tests don't work on big-endian systems. This change handles more of the tests added in CL 381317 like the other existing tests. Fixes #52723 Change-Id: Ie9e048e75dbe0b5aca61b51cd0c50d7d878ff6d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/404495 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-04sync/atomic: add typed atomic valuesRuss Cox
These implementations will inline to the lower-level primitives, but they hide the underlying values so that all accesses are forced to use the atomic APIs. They also allow the use of shorter names (methods instead of functions) at call sites, making code more readable. Pointer[T] also avoids conversions using unsafe.Pointer at call sites. Discussed on #47141. See also https://research.swtch.com/gomm for background. Fixes #50860. Change-Id: I0b178ee0c7747fa8985f8e48cd7b01063feb7dcc Reviewed-on: https://go-review.googlesource.com/c/go/+/381317 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-29sync/atomic: use consistent first-store-in-progress markerKeith Randall
We need to use the same marker everywhere. My CL to rename the marker (CL 241661) and the CL to add more uses of the marker under the old name (CL 241678) weren't coordinated with each other. Fixes #52612 Change-Id: I97023c0769e518491924ef457fe03bf64a2cefa6 Reviewed-on: https://go-review.googlesource.com/c/go/+/403094 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-06all: remove more leftover // +build linesTobias Klauser
CL 344955 and CL 359476 removed almost all // +build lines, but leaving some assembly files and generating scripts. Also, some files were added with // +build lines after CL 359476 was merged. Remove these or rename files where more appropriate. For #41184 Change-Id: I7eb85a498ed9788b42a636e775f261d755504ffa Reviewed-on: https://go-review.googlesource.com/c/go/+/361480 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-04sync/atomic: disable GC during TestHammerStoreLoadMichael Anthony Knyszek
TestHammerStoreLoad involves a stress test of StorePointer, which has a write barrier. The "pointer" that is being written is not a real value, which is generally fine (though not *really* safe) on 64-bit systems because they never point to an actual object. On 32-bit systems, however, this is much more likely. Because I can't figure out how to rewrite the test such that it still is testing the same conditions but is also using real pointers, just disable the GC during the test, and make sure there isn't one currently in progress. Fixes #49362. Change-Id: If81883fedf06568132e6484f40c820aa69027a9c Reviewed-on: https://go-review.googlesource.com/c/go/+/361455 Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-10-26sync/atomic: use a better first-store-in-progress markerKeith Randall
Unlike what the comment says, the GC can see this pointer. Might as well make it a real pointer, even though ^uintptr(0) isn't currently causing problems. Removed the comment about GC not seeing the pointer. Change-Id: I04bc1fd4848698bec6afb79bd5fda671dfc9a073 Reviewed-on: https://go-review.googlesource.com/c/go/+/241661 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Colin Arnott <colin@urandom.co.uk> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org>
2021-08-14sync/atomic: fix documentation for CompareAndSwapJeff Wentworth
Fixes #47699 The documentation for CompareAndSwap atomic/value incorrectly labelled the function as CompareAndSwapPointer. This PR fixes that. Change-Id: I6db08fdfe166570b775248fd24550f5d28e3434e GitHub-Last-Rev: 41f78707928f48c9cdac26b6a4f618d4284e1ca1 GitHub-Pull-Request: golang/go#47700 Reviewed-on: https://go-review.googlesource.com/c/go/+/342210 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Go Bot <gobot@golang.org>
2021-05-13all: add //go:build lines to assembly filesTobias Klauser
Don't add them to files in vendor and cmd/vendor though. These will be pulled in by updating the respective dependencies. For #41184 Change-Id: Icc57458c9b3033c347124323f33084c85b224c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/319389 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2021-05-04sync/atomic: add (*Value).Swap and (*Value).CompareAndSwapColin Arnott
The functions SwapPointer and CompareAndSwapPointer can be used to interact with unsafe.Pointer, however generally it is prefered to work with Value, due to its safer interface. As such, they have been added along with glue logic to maintain invariants Value guarantees. To meet these guarantees, the current implementation duplicates much of the Store function. Some of this is due to inexperience with concurrency and desire for correctness, but the lack of generic programming functionality does not help. Fixes #39351 Change-Id: I1aa394b1e70944736ac1e19de49fe861e1e46fba Reviewed-on: https://go-review.googlesource.com/c/go/+/241678 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-11-23sync: use 386 instead of x86-32 to refer to the 32 bit x86 architectureMartin Möhrmann
This aligns the naming with GOARCH using 386 as a build target for this architecture and makes it more easily found when searching for documentation related to the build target. Change-Id: I393bb89dd2f71e568124107b13e1b288fbd0c76a Reviewed-on: https://go-review.googlesource.com/c/go/+/271988 Trust: Martin Möhrmann <moehrmann@google.com> Run-TryBot: Martin Möhrmann <martisch@uos.de> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-16runtime/internal/atomic: panic nicely on unaligned 64-bit atomicsAustin Clements
On 386 and arm, unaligned 64-bit atomics aren't safe, so we check for this and panic. Currently, we panic by dereferencing nil, which may be expedient but is pretty user-hostile since it gives no hint of what the actual problem was. This CL replaces this with an actual panic. The only subtlety here is now the atomic assembly implementations are calling back into Go, so they have to play nicely with stack maps and stack scanning. On 386, this just requires declaring NO_LOCAL_POINTERS. On arm, this is somewhat more complicated: first, we have to move the alignment check into the functions that have Go signatures. Then we have to support both the tail call from these functions to the underlying implementation (which requires that they have no frame) and the call into Go to panic (which requires that they have a frame). We resolve this by forcing them to have no frame and setting up the frame manually just before the panic call. Change-Id: I19f1e860045df64088013db37a18acea47342c69 Reviewed-on: https://go-review.googlesource.com/c/go/+/262778 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2020-04-02sync/atomic: fix TestSwapPointer testKeith Randall
It plays way too loose with unsafe.Pointer rules. It runs afoul of the checkptr rules, so some race detector builds were failing. Fixes #38210 Change-Id: I5e1c78201d06295524fdedb3fe5b49d61446f443 Reviewed-on: https://go-review.googlesource.com/c/go/+/226880 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-03-19sync/atomic: remove panic64Daniel Martí
The func has been unused since https://golang.org/cl/93637 in 2018. Change-Id: I1cab6f265aa5058ac080fd7c7cbf0fe85370f073 Reviewed-on: https://go-review.googlesource.com/c/go/+/224077 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matt Layher <mdlayher@gmail.com> Reviewed-by: Austin Clements <austin@google.com>
2020-02-27all: fix incorrect channel and API usage in some unit testsZiheng Liu
This CL changes some unit test functions, making sure that these tests (and goroutines spawned during test) won't block. Since they are just test functions, I use one CL to fix them all. I hope this won't cause trouble to reviewers and can save time for us. There are three main categories of incorrect logic fixed by this CL: 1. Use testing.Fatal()/Fatalf() in spawned goroutines, which is forbidden by Go's document. 2. Channels are used in such a way that, when errors or timeout happen, the test will be blocked and never return. 3. Channels are used in such a way that, when errors or timeout happen, the test can return but some spawned goroutines will be leaked, occupying resource until all other tests return and the process is killed. Change-Id: I3df931ec380794a0cf1404e632c1dd57c65d63e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/219380 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-22sync/atomic: suppress checkptr errors for hammerStoreLoadPointerMatthew Dempsky
This test could be updated to use unsafe.Pointer arithmetic properly (e.g., see discussion at #34972), but it doesn't seem worthwhile. The test is just checking that LoadPointer and StorePointer are atomic. Updates #34972. Change-Id: I85a8d610c1766cd63136cae686aa8a240a362a18 Reviewed-on: https://go-review.googlesource.com/c/go/+/202597 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-10all: remove nacl (part 3, more amd64p32)Brad Fitzpatrick
Part 1: CL 199499 (GOOS nacl) Part 2: CL 200077 (amd64p32 files, toolchain) Part 3: stuff that arguably should've been part of Part 2, but I forgot one of my grep patterns when splitting the original CL up into two parts. This one might also have interesting stuff to resurrect for any future x32 ABI support. Updates #30439 Change-Id: I2b4143374a253a003666f3c69e776b7e456bdb9c Reviewed-on: https://go-review.googlesource.com/c/go/+/200318 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-09sync/atomic: add 32-bit MIPS to the 64-bit alignment requirementIan Lance Taylor
runtime/internal/atomic/atomic_mipsx.go enforces 64-bit alignment. Change-Id: Ifdc36e1c0322827711425054d10f1c52425a13fa Reviewed-on: https://go-review.googlesource.com/c/161697 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-03sync/atomic: redirect many functions to runtime/internal/atomicCherry Zhang
The implementation of atomics are inherently tricky. It would be good to have them implemented in a single place, instead of multiple copies. Mostly a simple redirect. On 386, some functions in sync/atomic have better implementations, which are moved to runtime/internal/atomic. On ARM, some functions in sync/atomic have better implementations. They are dropped by this CL, but restored with an improved version in a follow-up CL. On linux/arm, 64-bit CAS kernel helper is dropped, as we're trying to move away from kernel helpers. Fixes #23778. Change-Id: Icb9e1039acc92adbb2a371c34baaf0b79551c3ea Reviewed-on: https://go-review.googlesource.com/93637 Reviewed-by: Austin Clements <austin@google.com>
2018-04-18sync/atomic: use package prefix in examplesKevin Burke
Previously these examples declared "var v Value" but any caller would need to write "var v atomic.Value", so we should use the external package declaration form to avoid confusion about where Value comes from. Change-Id: Ic0b1a05fb6b700da61cfc8efca594c49a9bedb69 Reviewed-on: https://go-review.googlesource.com/107975 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-18runtime/internal/atomic: don't use Cas in atomic.Load on ARMYuval Pavel Zholkover
Instead issue a memory barrier on ARMv7 after reading the address. Fixes #23777 Change-Id: I7aff2ab0246af64b437ebe0b31d4b30d351890d8 Reviewed-on: https://go-review.googlesource.com/94275 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-27cmd/internal/obj/arm: add DMB instructionYuval Pavel Zholkover
Change-Id: Ib67a61d5b37af210ff15d60d72bd5238b9c2d0ca Reviewed-on: https://go-review.googlesource.com/94815 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>