From 807a7b3c29e58c991820a9447f8c55cc05eeeb00 Mon Sep 17 00:00:00 2001 From: Apprentice-Alchemist <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Fri, 16 Jan 2026 09:55:55 +0100 Subject: [PATCH] [neko] support condition variables --- std/neko/_std/sys/thread/Condition.hx | 41 ++++++++++++++++++++++++ tests/threads/src/cases/TestCondition.hx | 4 --- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 std/neko/_std/sys/thread/Condition.hx diff --git a/std/neko/_std/sys/thread/Condition.hx b/std/neko/_std/sys/thread/Condition.hx new file mode 100644 index 00000000000..ecd87d4c895 --- /dev/null +++ b/std/neko/_std/sys/thread/Condition.hx @@ -0,0 +1,41 @@ +package sys.thread; + +class Condition { + var c:Dynamic; + + public function new():Void { + c = cond_create(); + } + + public function acquire():Void { + cond_acquire(c); + } + + public function tryAcquire():Bool { + return cond_try_acquire(c); + } + + public function release():Void { + cond_release(c); + } + + public function wait():Void { + cond_wait(c); + } + + public function signal():Void { + cond_signal(c); + } + + public function broadcast():Void { + cond_broadcast(c); + } + + static var cond_create = neko.Lib.loadLazy("std", "cond_create", 0); + static var cond_try_acquire = neko.Lib.loadLazy("std", "cond_try_acquire", 1); + static var cond_acquire = neko.Lib.loadLazy("std", "cond_acquire", 1); + static var cond_release = neko.Lib.loadLazy("std", "cond_release", 1); + static var cond_wait = neko.Lib.loadLazy("std", "cond_wait", 1); + static var cond_signal = neko.Lib.loadLazy("std", "cond_signal", 1); + static var cond_broadcast = neko.Lib.loadLazy("std", "cond_broadcast", 1); +} diff --git a/tests/threads/src/cases/TestCondition.hx b/tests/threads/src/cases/TestCondition.hx index aa9f9f979dd..9700529880b 100644 --- a/tests/threads/src/cases/TestCondition.hx +++ b/tests/threads/src/cases/TestCondition.hx @@ -1,12 +1,9 @@ package cases; -#if !neko import sys.thread.Condition; import sys.thread.Thread; -#end class TestCondition extends utest.Test { - #if !neko function test() { final cond = new Condition(); cond.acquire(); @@ -19,5 +16,4 @@ class TestCondition extends utest.Test { cond.release(); utest.Assert.pass(); } - #end }