This is automatic generated document for things in Swow\Semaphore class
Class Semaphore
A counting semaphore that works across threads.
Methods
Method __construct
Create a semaphore. This method does not yield.
Param int $value initial permit count, from 0 to UINT_MAX
Throws \ValueError when the value is out of range. Throws \Swow\SyncException when the semaphore is already constructed.
Method __serialize
Serialize the semaphore by shared object id.
The serialized form does not copy the semaphore state.
Throws \Swow\SyncException when the semaphore is not constructed.
Method __unserialize
Restore the semaphore from a shared object id.
Throws \Swow\SyncException when the data is invalid or the object is gone.
Method acquire
Take one permit.
In a coroutine, this method suspends the current coroutine when the count is zero.
context switching may happen here
Param int $timeout timeout in milliseconds, -1 waits forever
Returns bool false on timeout
Throws \Swow\SyncException when the caller cannot wait for the semaphore.
Method getValue
Return the current permit count.
Method getWaiterCount
Return the number of waiters.
Method release
Add permits and wake waiters.
A count of 0 does nothing.
Param int $count number of permits to add
Throws \ValueError when the count is negative.
Method tryAcquire
Try to take one permit without waiting.
Returns bool true when a permit was taken