Fix wait condition and ordering in send().
This commit is contained in:
parent
4052afa31d
commit
c4e92faaf7
@ -138,12 +138,12 @@ func (s *state[T]) send(value T, buf *circ.B[T], cond *sync.Cond) {
|
|||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
for {
|
for {
|
||||||
|
for !s.closed && !buf.CanPush() {
|
||||||
|
cond.Wait()
|
||||||
|
}
|
||||||
if s.closed {
|
if s.closed {
|
||||||
panic("send on closed queue")
|
panic("send on closed queue")
|
||||||
}
|
}
|
||||||
for !buf.CanPush() {
|
|
||||||
cond.Wait()
|
|
||||||
}
|
|
||||||
if buf.CanPush() {
|
if buf.CanPush() {
|
||||||
buf.PushBack(value)
|
buf.PushBack(value)
|
||||||
s.canRecv.Broadcast()
|
s.canRecv.Broadcast()
|
||||||
|
Loading…
Reference in New Issue
Block a user