init($locks); } /** * Initializes the semaphore with a given number of locks. * * @param int $locks */ private function init(int $locks) { if ($locks < 1) { throw new \Error("The number of locks should be a positive integer"); } $this->semaphore = new Internal\Semaphore($locks); $this->maxLocks = $locks; } /** * {@inheritdoc} */ public function count(): int { return $this->semaphore->count(); } /** * {@inheritdoc} */ public function getSize(): int { return $this->maxLocks; } /** * {@inheritdoc} */ public function acquire(): Promise { return $this->semaphore->acquire(); } /** * Clones the semaphore, creating a new instance with the same number of locks, all available. */ public function __clone() { $this->init($this->getSize()); } }