Semaphore.hx 918 B

123456789101112131415161718192021222324252627282930313233
  1. package sys.thread;
  2. #if (!target.threaded)
  3. #error "This class is not available on this target"
  4. #end
  5. @:coreApi extern class Semaphore {
  6. /**
  7. Creates a new semaphore with an initial value.
  8. **/
  9. public function new(value:Int):Void;
  10. /**
  11. Locks the semaphore.
  12. If the value of the semaphore is zero, then the thread will block until it is able to lock the semaphore.
  13. If the value is non-zero, it is decreased by one.
  14. **/
  15. public function acquire():Void;
  16. /**
  17. Try to lock the semaphore.
  18. If the value of the semaphore is zero, `false` is returned, else the value is increased.
  19. If `timeout` is specified, this function will block until the thread is able to acquire the semaphore, or the timout expires.
  20. `timeout` is in seconds.
  21. **/
  22. public function tryAcquire(?timeout:Float):Bool;
  23. /**
  24. Release the semaphore.
  25. The value of the semaphore is increased by one.
  26. **/
  27. public function release():Void;
  28. }