@@ 163-190 (lines=28) @@ | ||
160 | ||
161 | if ($mode & self::LOCK_CAPABILITY_EXCLUSIVE) { |
|
162 | ||
163 | if ($mode & self::LOCK_CAPABILITY_NOBLOCK) { |
|
164 | ||
165 | // this does not block |
|
166 | $this->isAcquired = $this->lock(); |
|
167 | ||
168 | if (!$this->isAcquired) { |
|
169 | throw new LockAcquireWouldBlockException('could not acquire lock'); |
|
170 | } |
|
171 | } else { |
|
172 | ||
173 | // try to acquire the lock till timeout is reached |
|
174 | $waited = 0; |
|
175 | do { |
|
176 | $start = time(); |
|
177 | ||
178 | // this blocks till the lock gets released |
|
179 | $this->wait($this->blTo - $waited); |
|
180 | ||
181 | $waited += time() - $start; |
|
182 | ||
183 | if ($waited > $this->blTo) { |
|
184 | throw new LockAcquireException('could not acquire lock'); |
|
185 | } |
|
186 | ||
187 | $this->isAcquired = $this->lock(); |
|
188 | ||
189 | } while (!$this->isAcquired); |
|
190 | } |
|
191 | ||
192 | } else { |
|
193 | throw new LockAcquireException('insufficient capabilities'); |
@@ 166-198 (lines=33) @@ | ||
163 | } |
|
164 | ||
165 | //if ($mode & self::LOCK_CAPABILITY_EXCLUSIVE) { |
|
166 | if ($mode) { |
|
167 | ||
168 | //if ($mode & self::LOCK_CAPABILITY_NOBLOCK) { |
|
169 | if (!$mode) { |
|
170 | ||
171 | // this does not block |
|
172 | $this->isAcquired = $this->lock(); |
|
173 | ||
174 | if (!$this->isAcquired) { |
|
175 | //throw new LockAcquireWouldBlockException('could not acquire lock'); |
|
176 | throw new \Exception('could not acquire lock'); |
|
177 | } |
|
178 | } else { |
|
179 | ||
180 | // try to acquire the lock till $blTo is reached |
|
181 | $waited = 0; |
|
182 | do { |
|
183 | $start = time(); |
|
184 | ||
185 | // this blocks till the lock gets released |
|
186 | $this->wait($this->blTo - $waited); |
|
187 | ||
188 | $waited += time() - $start; |
|
189 | ||
190 | $this->isAcquired = $this->lock(); |
|
191 | ||
192 | } while (!$this->isAcquired && $waited < $this->blTo); |
|
193 | } |
|
194 | ||
195 | } else { |
|
196 | //throw new LockAcquireException('insufficient capabilities'); |
|
197 | throw new \Exception('insufficient capabilities'); |
|
198 | } |
|
199 | ||
200 | echo $this->id.' acquired lock: '.$this->value.PHP_EOL; |
|
201 |