From f1f75897b3689506cc896f8acc866b54aaa8b856 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 14 Apr 2022 14:00:57 +0300 Subject: [PATCH] sync: use asserts in channel code only when `-d debug` is passed --- vlib/sync/bench/channel_bench_v.v | 4 +++- vlib/sync/channels.c.v | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vlib/sync/bench/channel_bench_v.v b/vlib/sync/bench/channel_bench_v.v index 54dcfe974b..48f026989b 100644 --- a/vlib/sync/bench/channel_bench_v.v +++ b/vlib/sync/bench/channel_bench_v.v @@ -41,7 +41,9 @@ fn main() { go do_rec(ch, resch, n) no -= n } - assert no == 0 + $if debug { + assert no == 0 + } no = nobj for i in 0 .. nsend { n := no / (nsend - i) diff --git a/vlib/sync/channels.c.v b/vlib/sync/channels.c.v index 1854809fb5..ee753be39c 100644 --- a/vlib/sync/channels.c.v +++ b/vlib/sync/channels.c.v @@ -547,8 +547,10 @@ fn (mut ch Channel) try_pop_priv(dest voidptr, no_block bool) ChanState { // -2 if all channels are closed pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []voidptr, timeout time.Duration) int { - assert channels.len == dir.len - assert dir.len == objrefs.len + $if debug { + assert channels.len == dir.len + assert dir.len == objrefs.len + } mut subscr := []Subscription{len: channels.len} mut sem := unsafe { Semaphore{} } sem.init(0)