don't use atomic operations to initialize refcounts

It's not necessary, as un-initialized refcounts haven't been shared across
goroutines yet. This saves us a bunch of slow atomic operations.

PiperOrigin-RevId: 536472388
This commit is contained in:
Kevin Krakauer
2023-05-30 12:18:09 -07:00
committed by gVisor bot
parent f4a4cde7dd
commit 08ff84c6e7
+3 -1
View File
@@ -63,7 +63,9 @@ type Refs struct {
// InitRefs initializes r with one reference and, if enabled, activates leak
// checking.
func (r *Refs) InitRefs() {
r.refCount.Store(1)
// We can use RacyStore because the refs can't be shared until after
// InitRefs is called, and thus it's safe to use non-atomic operations.
r.refCount.RacyStore(1)
refs.Register(r)
}