mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Fix deadlock on sending to full, buffered, closed Chan
This will also keep messages from being sent to closed, buffered channels in general.
This commit is contained in:
@@ -164,12 +164,17 @@ send_raw :: proc "contextless" (c: ^Raw_Chan, msg_in: rawptr) -> (ok: bool) {
|
|||||||
}
|
}
|
||||||
if c.queue != nil { // buffered
|
if c.queue != nil { // buffered
|
||||||
sync.guard(&c.mutex)
|
sync.guard(&c.mutex)
|
||||||
for c.queue.len == c.queue.cap {
|
for !sync.atomic_load(&c.closed) &&
|
||||||
|
c.queue.len == c.queue.cap {
|
||||||
sync.atomic_add(&c.w_waiting, 1)
|
sync.atomic_add(&c.w_waiting, 1)
|
||||||
sync.wait(&c.w_cond, &c.mutex)
|
sync.wait(&c.w_cond, &c.mutex)
|
||||||
sync.atomic_sub(&c.w_waiting, 1)
|
sync.atomic_sub(&c.w_waiting, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sync.atomic_load(&c.closed) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
ok = raw_queue_push(c.queue, msg_in)
|
ok = raw_queue_push(c.queue, msg_in)
|
||||||
if sync.atomic_load(&c.r_waiting) > 0 {
|
if sync.atomic_load(&c.r_waiting) > 0 {
|
||||||
sync.signal(&c.r_cond)
|
sync.signal(&c.r_cond)
|
||||||
|
|||||||
Reference in New Issue
Block a user