File tree 2 files changed +5
-5
lines changed 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ type Once struct {
25
25
// The hot path is inlined at every call site.
26
26
// Placing done first allows more compact instructions on some architectures (amd64/386),
27
27
// and fewer instructions (to calculate offset) on other architectures.
28
- done atomic.Uint32
28
+ done atomic.Bool
29
29
m Mutex
30
30
}
31
31
@@ -64,7 +64,7 @@ func (o *Once) Do(f func()) {
64
64
// This is why the slow path falls back to a mutex, and why
65
65
// the o.done.Store must be delayed until after f returns.
66
66
67
- if o .done .Load () == 0 {
67
+ if ! o .done .Load () {
68
68
// Outlined slow-path to allow inlining of the fast-path.
69
69
o .doSlow (f )
70
70
}
@@ -73,8 +73,8 @@ func (o *Once) Do(f func()) {
73
73
func (o * Once ) doSlow (f func ()) {
74
74
o .m .Lock ()
75
75
defer o .m .Unlock ()
76
- if o .done .Load () == 0 {
77
- defer o .done .Store (1 )
76
+ if ! o .done .Load () {
77
+ defer o .done .Store (true )
78
78
f ()
79
79
}
80
80
}
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ var once *sync.Once
37
37
38
38
func small7 () { // ERROR "can inline small7"
39
39
// the Do fast path should be inlined
40
- once .Do (small5 ) // ERROR "inlining call to sync\.\(\*Once\)\.Do" "inlining call to atomic\.\(\*Uint32 \)\.Load"
40
+ once .Do (small5 ) // ERROR "inlining call to sync\.\(\*Once\)\.Do" "inlining call to atomic\.\(\*Bool \)\.Load"
41
41
}
42
42
43
43
var rwmutex * sync.RWMutex
You can’t perform that action at this time.
0 commit comments