Semaphore.hx 585 B

1234567891011121314151617181920212223242526
  1. package sys.thread;
  2. import java.util.concurrent.TimeUnit;
  3. @:noDoc
  4. @:coreApi
  5. @:native('haxe.java.vm.Semaphore')
  6. class Semaphore {
  7. final native:java.util.concurrent.Semaphore;
  8. public function new(value:Int):Void {
  9. this.native = new java.util.concurrent.Semaphore(value);
  10. }
  11. public function acquire():Void {
  12. native.acquire();
  13. }
  14. public function tryAcquire(?timeout:Float):Bool {
  15. return timeout == null ? native.tryAcquire() : native.tryAcquire(haxe.Int64.fromFloat(timeout * 1000000000),TimeUnit.NANOSECONDS);
  16. }
  17. public function release():Void {
  18. native.release();
  19. }
  20. }