Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions std/neko/_std/sys/thread/Semaphore.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sys.thread;

@:coreApi class Semaphore {
var s:Dynamic;

public function new(value:Int):Void {
s = semaphore_create(value);
}

public function acquire():Void {
semaphore_acquire(s);
}

public function tryAcquire(?timeout:Float):Bool {
return semaphore_try_acquire(s, timeout);
}

public function release():Void {
semaphore_release(s);
}

static var semaphore_create = neko.Lib.loadLazy("std", "semaphore_create", 1);
static var semaphore_try_acquire = neko.Lib.loadLazy("std", "semaphore_try_acquire", 2);
static var semaphore_acquire = neko.Lib.loadLazy("std", "semaphore_acquire", 1);
static var semaphore_release = neko.Lib.loadLazy("std", "semaphore_release", 1);
}
4 changes: 0 additions & 4 deletions tests/threads/src/cases/TestSemaphore.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package cases;

#if !neko
import sys.thread.Semaphore;
#end

class TestSemaphore extends utest.Test {
#if !neko
function test() {
var m = new Semaphore(3);
m.acquire();
Expand All @@ -17,5 +14,4 @@ class TestSemaphore extends utest.Test {
m.release();
m.release();
}
#end
}