1
0
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:
Aaron Piotrowski 2015-09-01 20:58:22 -05:00
parent c5ff71f4b4
commit 172c64c583
2 changed files with 2 additions and 12 deletions

View File

@ -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);
}

View File

@ -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);
}