Condition.hx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package sys.thread;
  2. #if (!target.threaded)
  3. #error "This class is not available on this target"
  4. #end
  5. /**
  6. Creates a new condition variable.
  7. Conditions variables can be used to block one or more threads at the same time,
  8. until another thread modifies a shared variable (the condition)
  9. and signals the condition variable.
  10. **/
  11. @:coreApi extern class Condition {
  12. /**
  13. Create a new condition variable.
  14. A thread that waits on a newly created condition variable will block.
  15. **/
  16. function new():Void;
  17. /**
  18. Acquires the internal mutex.
  19. **/
  20. function acquire():Void;
  21. /**
  22. Tries to acquire the internal mutex.
  23. @see `Mutex.tryAcquire`
  24. **/
  25. function tryAcquire():Bool;
  26. /***
  27. Releases the internal mutex.
  28. **/
  29. function release():Void;
  30. /**
  31. Atomically releases the mutex and blocks until the condition variable pointed is signaled by a call to
  32. `signal` or to `broadcast`. When the calling thread becomes unblocked it
  33. acquires the internal mutex.
  34. The internal mutex should be locked before this function is called.
  35. **/
  36. function wait():Void;
  37. /**
  38. Unblocks one of the threads that are blocked on the
  39. condition variable at the time of the call. If no threads are blocked
  40. on the condition variable at the time of the call, the function does nothing.
  41. **/
  42. function signal():Void;
  43. /**
  44. Unblocks all of the threads that are blocked on the
  45. condition variable at the time of the call. If no threads are blocked
  46. on the condition variable at the time of the call, the function does
  47. nothing.
  48. **/
  49. function broadcast():Void;
  50. }