Fix wait condition and ordering in send().

This commit is contained in:
Sam Fredrickson 2023-03-01 01:03:31 -08:00
parent 4052afa31d
commit c4e92faaf7
1 changed files with 3 additions and 3 deletions

View File

@ -138,12 +138,12 @@ func (s *state[T]) send(value T, buf *circ.B[T], cond *sync.Cond) {
s.mu.Lock()
defer s.mu.Unlock()
for {
for !s.closed && !buf.CanPush() {
cond.Wait()
}
if s.closed {
panic("send on closed queue")
}
for !buf.CanPush() {
cond.Wait()
}
if buf.CanPush() {
buf.PushBack(value)
s.canRecv.Broadcast()