diff --git a/src/Threading/Internal/Mutex.php b/src/Threading/Internal/Mutex.php index 29650d4..b4c69f8 100644 --- a/src/Threading/Internal/Mutex.php +++ b/src/Threading/Internal/Mutex.php @@ -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); } diff --git a/src/Threading/Internal/Semaphore.php b/src/Threading/Internal/Semaphore.php index 52a6817..ce7b155 100644 --- a/src/Threading/Internal/Semaphore.php +++ b/src/Threading/Internal/Semaphore.php @@ -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); }