| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace malkusch\lock\exception; |
| 6 |
|
| 7 |
/** |
| 8 |
* Execution outside lock exception. |
| 9 |
* |
| 10 |
* This exception should be thrown when for example the lock is released or the |
| 11 |
* lock times out before the critical code has finished execution. This is a |
| 12 |
* serious exception. Side effects might have happened while the critical code |
| 13 |
* was executed outside of the lock which should not be trusted to be valid. |
| 14 |
* |
| 15 |
* Should only be used in contexts where the is being released. |
| 16 |
* |
| 17 |
* @see \malkusch\lock\mutex\SpinlockMutex::unlock() |
| 18 |
* |
| 19 |
* @author Petr Levtonov <petr@levtonov.com> |
| 20 |
* @license WTFPL |
| 21 |
*/ |
| 22 |
class ExecutionOutsideLockException extends LockReleaseException |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Creates a new instance of the ExecutionOutsideLockException class. |
| 26 |
* |
| 27 |
* @param float $elapsedTime Total elapsed time of the synchronized code |
| 28 |
* callback execution. |
| 29 |
* @param int $timeout The lock timeout in seconds. |
| 30 |
* @return self Execution outside lock exception. |
| 31 |
*/ |
| 32 |
public static function create(float $elapsedTime, int $timeout): self |
| 33 |
{ |
| 34 |
return new self(\sprintf( |
| 35 |
'The code executed for %.2F seconds. But the timeout is %d ' . |
| 36 |
'seconds. The last %.2F seconds were executed outside of the lock.', |
| 37 |
$elapsedTime, |
| 38 |
$timeout, |
| 39 |
$elapsedTime - $timeout |
| 40 |
)); |
| 41 |
} |
| 42 |
} |
| 43 |
|