aboutsummaryrefslogtreecommitdiff
path: root/core/sync/chan
diff options
context:
space:
mode:
authorJack Mordaunt <jackmordaunt.dev@gmail.com>2025-06-08 18:31:26 -0300
committerJack Mordaunt <jackmordaunt.dev@gmail.com>2025-06-12 16:14:52 -0300
commitfaae81ba61eb835932dec4458aec9e2c0b04772d (patch)
treeebc00dcd2266c6834c7960facf14a7fc56caa9c9 /core/sync/chan
parent4043be85678e979996286c5269cfa35a7f10edac (diff)
core/sync/chan.try_select_raw: test hook for testing the toctou
This is necessary because we need to allow the test guarantee against a rare condition: where a third-party thread steals a value between the validity checks can_{send,recv} and the channel operation try_{send,recv}.
Diffstat (limited to 'core/sync/chan')
-rw-r--r--core/sync/chan/chan.odin14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/sync/chan/chan.odin b/core/sync/chan/chan.odin
index 2c34f7bb3..17c251158 100644
--- a/core/sync/chan/chan.odin
+++ b/core/sync/chan/chan.odin
@@ -7,6 +7,14 @@ import "core:mem"
import "core:sync"
import "core:math/rand"
+when ODIN_TEST {
+/*
+Hook for testing _try_select_raw allowing the test harness to manipulate the
+channels prior to the select actually operating on them.
+*/
+__try_select_raw_pause : proc() = nil
+}
+
/*
Determines what operations `Chan` supports.
*/
@@ -1221,6 +1229,12 @@ try_select_raw :: proc "odin" (recvs: []^Raw_Chan, sends: []^Raw_Chan, send_msgs
return -1, .None
}
+ when ODIN_TEST {
+ if __try_select_raw_pause != nil {
+ __try_select_raw_pause()
+ }
+ }
+
candidate_idx := rand.int_max(count) if count > 0 else 0
sel := candidates[candidate_idx]