mirror of
https://github.com/danog/parallel.git
synced 2024-11-27 04:44:56 +01:00
Fix threaded mutex and semaphore
This commit is contained in:
parent
c5ff71f4b4
commit
172c64c583
@ -27,7 +27,7 @@ class Mutex extends \Threaded
|
||||
return ($this->lock ? $this->lock = false : true);
|
||||
};
|
||||
|
||||
while ($this->lock && $this->synchronized($tsl)) {
|
||||
while (!$this->lock || $this->synchronized($tsl)) {
|
||||
yield Coroutine\sleep(self::LATENCY_TIMEOUT);
|
||||
}
|
||||
|
||||
|
@ -13,21 +13,11 @@ class Semaphore extends \Threaded
|
||||
{
|
||||
const LATENCY_TIMEOUT = 0.01; // 10 ms
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $nextId = 0;
|
||||
|
||||
/**
|
||||
* @var int The number of available locks.
|
||||
*/
|
||||
private $locks;
|
||||
|
||||
/**
|
||||
* @var array A queue of lock requests.
|
||||
*/
|
||||
private $waitQueue = [];
|
||||
|
||||
/**
|
||||
* Creates a new semaphore with a given number of locks.
|
||||
*
|
||||
@ -72,7 +62,7 @@ class Semaphore extends \Threaded
|
||||
return true;
|
||||
};
|
||||
|
||||
while ($this->locks > 0 && $this->synchronized($tsl)) {
|
||||
while ($this->locks < 1 || $this->synchronized($tsl)) {
|
||||
yield Coroutine\sleep(self::LATENCY_TIMEOUT);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user