Skip to content

Commit

Permalink
Remove pointer to broadcast channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
marusama committed Dec 11, 2017
1 parent 2f90392 commit e8e0bd7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions semaphore.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type semaphore struct {

// broadcast fields
lock sync.RWMutex
broadcastCh *chan struct{}
broadcastCh chan struct{}
}

// New initializes a new instance of the Semaphore, specifying the maximum number of concurrent entries.
Expand All @@ -75,7 +75,7 @@ func New(limit int) Semaphore {
broadcastCh := make(chan struct{})
return &semaphore{
state: uint64(limit) << 32,
broadcastCh: &broadcastCh,
broadcastCh: broadcastCh,
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func (s *semaphore) Acquire(ctx context.Context, n int) error {
} else {
// semaphore is full, let's wait
s.lock.RLock()
broadcastCh := *s.broadcastCh
broadcastCh := s.broadcastCh
s.lock.RUnlock()

if ctx != nil {
Expand Down Expand Up @@ -173,11 +173,11 @@ func (s *semaphore) Release(n int) int {
newBroadcastCh := make(chan struct{})
s.lock.Lock()
oldBroadcastCh := s.broadcastCh
s.broadcastCh = &newBroadcastCh
s.broadcastCh = newBroadcastCh
s.lock.Unlock()

// send broadcast signal
close(*oldBroadcastCh)
close(oldBroadcastCh)
}
return int(count)
}
Expand All @@ -194,11 +194,11 @@ func (s *semaphore) SetLimit(limit int) {
newBroadcastCh := make(chan struct{})
s.lock.Lock()
oldBroadcastCh := s.broadcastCh
s.broadcastCh = &newBroadcastCh
s.broadcastCh = newBroadcastCh
s.lock.Unlock()

// send broadcast signal
close(*oldBroadcastCh)
close(oldBroadcastCh)
return
}
}
Expand Down

0 comments on commit e8e0bd7

Please sign in to comment.