From e72d0ba8042f3b2ebd7d94aa7b4dae676827e952 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 8 Sep 2024 14:11:05 +0100 Subject: [PATCH] Move around mutex guard --- core/sync/chan/chan.odin | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/sync/chan/chan.odin b/core/sync/chan/chan.odin index 0c98124dec3..a3e0bc21fa8 100644 --- a/core/sync/chan/chan.odin +++ b/core/sync/chan/chan.odin @@ -421,21 +421,20 @@ raw_queue_pop :: proc "contextless" (q: ^Raw_Queue) -> (data: rawptr) { @(require_results) can_recv :: proc "contextless" (c: ^Raw_Chan) -> bool { + sync.guard(&c.mutex) if is_buffered(c) { return len(c) > 0 } - sync.guard(&c.mutex) return sync.atomic_load(&c.w_waiting) > 0 } @(require_results) can_send :: proc "contextless" (c: ^Raw_Chan) -> bool { + sync.guard(&c.mutex) if is_buffered(c) { - sync.guard(&c.mutex) return len(c) < cap(c) } - sync.guard(&c.mutex) return sync.atomic_load(&c.r_waiting) > 0 }