Skip to content

Commit

Permalink
schedgroup: remove pointer from Group.waiting
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <[email protected]>
  • Loading branch information
mdlayher committed Apr 6, 2022
1 parent e25c04c commit 8b9c481
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// more tasks.
type Group struct {
// Atomics must come first per sync/atomic.
waiting *uint32
waiting uint32

// Context/cancelation support.
ctx context.Context
Expand All @@ -41,8 +41,6 @@ func New(ctx context.Context) *Group {
mctx, cancel := context.WithCancel(ctx)

g := &Group{
waiting: new(uint32),

ctx: ctx,
cancel: cancel,

Expand Down Expand Up @@ -73,7 +71,7 @@ func (g *Group) Delay(delay time.Duration, fn func()) {
//
// If Schedule is called after a call to Wait, Schedule will panic.
func (g *Group) Schedule(when time.Time, fn func()) {
if atomic.LoadUint32(g.waiting) != 0 {
if atomic.LoadUint32(&g.waiting) != 0 {
panic("schedgroup: attempted to schedule task after Group.Wait was called")
}

Expand Down Expand Up @@ -102,7 +100,7 @@ func (g *Group) Schedule(when time.Time, fn func()) {
// Once Wait is called, any further calls to Delay or Schedule will panic. If
// Wait is called more than once, Wait will panic.
func (g *Group) Wait() error {
if v := atomic.SwapUint32(g.waiting, 1); v != 0 {
if v := atomic.SwapUint32(&g.waiting, 1); v != 0 {
panic("schedgroup: multiple calls to Group.Wait")
}

Expand Down

0 comments on commit 8b9c481

Please sign in to comment.