Semaphore.hx 452 B

12345678910111213141516171819202122
  1. package sys.thread;
  2. @:coreApi
  3. class Semaphore {
  4. final native:cs.system.threading.Semaphore;
  5. public function new(value:Int):Void {
  6. this.native = new cs.system.threading.Semaphore(value, 0x7FFFFFFF);
  7. }
  8. public function acquire():Void {
  9. native.WaitOne();
  10. }
  11. public function tryAcquire(?timeout:Float):Bool {
  12. return native.WaitOne(timeout == null ? 0 : Std.int(timeout * 1000));
  13. }
  14. public function release():Void {
  15. native.Release();
  16. }
  17. }