Skip to content

Commit 41509dd

Browse files
authored
Rename NoMutex class to NullMutex (#74)
1 parent df6a8f6 commit 41509dd

14 files changed

+64
-79
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ implementations or create/extend your own implementation.
173173
#### FlockMutex
174174

175175
The **FlockMutex** is a lock implementation based on
176-
[`flock()`](http://php.net/manual/en/function.flock.php).
176+
[`flock()`](https://php.net/manual/en/function.flock.php).
177177

178178
Example:
179179
```php
@@ -194,7 +194,7 @@ extension if possible or busy waiting if not.
194194
#### MemcachedMutex
195195

196196
The **MemcachedMutex** is a spinlock implementation which uses the
197-
[`Memcached` extension](http://php.net/manual/en/book.memcached.php).
197+
[`Memcached` extension](https://php.net/manual/en/book.memcached.php).
198198

199199
Example:
200200
```php
@@ -215,7 +215,7 @@ $mutex->synchronized(function () use ($bankAccount, $amount) {
215215
#### RedisMutex
216216

217217
The **RedisMutex** is the distributed lock implementation of
218-
[RedLock](http://redis.io/topics/distlock) which supports the
218+
[RedLock](https://redis.io/topics/distlock#the-redlock-algorithm) which supports the
219219
[`phpredis` extension](https://github.com/phpredis/phpredis)
220220
or [`Predis` API](https://github.com/nrk/predis).
221221

@@ -244,7 +244,7 @@ $mutex->synchronized(function () use ($bankAccount, $amount) {
244244
#### SemaphoreMutex
245245

246246
The **SemaphoreMutex** is a lock implementation based on
247-
[Semaphore](http://php.net/manual/en/ref.sem.php).
247+
[Semaphore](https://php.net/manual/en/ref.sem.php).
248248

249249
Example:
250250
```php
@@ -330,9 +330,9 @@ Commercial support is available.
330330

331331
This project is free and is licensed under the MIT.
332332

333-
[1]: http://semver.org/
333+
[1]: https://semver.org/
334334
[2]: https://github.com/nrk/predis
335-
[3]: http://php.net/manual/en/book.pcntl.php
335+
[3]: https://php.net/manual/en/book.pcntl.php
336336
[4]: https://getcomposer.org/
337337
[5]: https://github.com/php-lock/lock/blob/3ca295ccda/src/Mutex/Mutex.php#L15
338338
[6]: https://github.com/php-lock/lock/blob/3ca295ccda/src/Mutex/Mutex.php#L38

src/Exception/ExecutionOutsideLockException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
/**
1111
* This exception should be thrown when for example the lock is released or the
12-
* lock times out before the critical code has finished execution. This is a
13-
* serious exception. Side effects might have happened while the critical code
12+
* lock times out before the critical code has finished execution.
13+
*
14+
* This is a serious exception. Side effects might have happened while the critical code
1415
* was executed outside of the lock which should not be trusted to be valid.
1516
*
1617
* Should only be used in contexts where the lock is being released.

src/Mutex/AbstractRedlockMutex.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
*
1717
* @template TClient of object
1818
*
19-
* @see http://redis.io/topics/distlock
19+
* @internal
20+
*
21+
* @see https://redis.io/topics/distlock#the-redlock-algorithm
2022
*/
2123
abstract class AbstractRedlockMutex extends AbstractSpinlockWithTokenMutex implements LoggerAwareInterface
2224
{

src/Mutex/Mutex.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function synchronized(callable $code);
3838
/**
3939
* Performs a double-checked locking pattern.
4040
*
41-
* Call {@link \Malkusch\Lock\Util\DoubleCheckedLocking::then()} on the
42-
* returned object.
41+
* Call {@link DoubleCheckedLocking::then()} on the returned object.
4342
*
4443
* Example:
4544
* <code>

src/Mutex/MySQLMutex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(\PDO $PDO, string $name, float $acquireTimeout = 0)
2727
$namePrefix = LockUtil::getInstance()->getKeyPrefix() . ':';
2828

2929
if (\strlen($name) > 64 - \strlen($namePrefix)) {
30-
throw new \InvalidArgumentException('The maximum length of the lock name is ' . (64 - \strlen($namePrefix)) . ' characters');
30+
throw new \InvalidArgumentException('The maximum length of the database lock name is ' . (64 - \strlen($namePrefix)) . ' characters');
3131
}
3232

3333
$this->name = $namePrefix . $name;

src/Mutex/NoMutex.php renamed to src/Mutex/NullMutex.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
namespace Malkusch\Lock\Mutex;
66

77
/**
8-
* This mutex doesn't lock at all.
9-
*
10-
* Synchronization is not provided! This mutex is just implementing the
11-
* interface without locking.
8+
* This mutex does not lock at all.
129
*/
13-
class NoMutex extends AbstractMutex
10+
class NullMutex extends AbstractMutex
1411
{
1512
#[\Override]
1613
public function synchronized(callable $code)

src/Mutex/RedisMutex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @extends AbstractRedlockMutex<TClient>
1919
*
20-
* @see http://redis.io/topics/distlock
20+
* @see https://redis.io/topics/distlock#the-redlock-algorithm
2121
*/
2222
class RedisMutex extends AbstractRedlockMutex
2323
{
@@ -122,7 +122,7 @@ protected function evalScript(object $client, string $luaScript, array $keys, ar
122122
}
123123
} else {
124124
try {
125-
return $client->eval($luaScript, count($keys), ...[...$keys, ...$arguments]);
125+
return $client->eval($luaScript, count($keys), ...$keys, ...$arguments);
126126
} catch (PredisException $e) {
127127
throw new LockReleaseException('Failed to release lock', 0, $e);
128128
}

src/Mutex/SemaphoreMutex.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
*/
1313
class SemaphoreMutex extends AbstractLockMutex
1414
{
15-
/** @var \SysvSemaphore|resource The semaphore id */
15+
/** @var \SysvSemaphore|resource */
1616
private $semaphore;
1717

1818
/**
19-
* Use {@link sem_get()} to create the semaphore id.
19+
* Use {@link sem_get()} to create the semaphore.
2020
*
2121
* Example:
2222
* <code>
2323
* $semaphore = sem_get(ftok(__FILE__, 'a'));
2424
* $mutex = new SemaphoreMutex($semaphore);
2525
* </code>
2626
*
27-
* @param \SysvSemaphore|resource $semaphore The semaphore id
27+
* @param \SysvSemaphore|resource $semaphore
2828
*/
2929
public function __construct($semaphore)
3030
{

src/Util/DoubleCheckedLocking.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The double-checked locking pattern.
1313
*
1414
* You should not instantiate this class directly. Use
15-
* {@link \Malkusch\Lock\Mutex\Mutex::check()}.
15+
* {@link Mutex::check()}.
1616
*
1717
* @internal
1818
*/
@@ -24,9 +24,8 @@ class DoubleCheckedLocking
2424
private $check;
2525

2626
/**
27-
* @param Mutex $mutex Provides methods for exclusive code execution
28-
* @param callable(): bool $check Callback that decides if the lock should be acquired and if the critical code
29-
* callback should be executed after acquiring the lock
27+
* @param callable(): bool $check Callback that decides if the lock should be acquired and is rechecked
28+
* after a lock has been acquired
3029
*/
3130
public function __construct(Mutex $mutex, callable $check)
3231
{
@@ -35,17 +34,12 @@ public function __construct(Mutex $mutex, callable $check)
3534
}
3635

3736
/**
38-
* Executes a synchronized callback only after the check callback passes
39-
* before and after acquiring the lock.
40-
*
41-
* If then returns boolean boolean false, the check did not pass before or
42-
* after acquiring the lock. A boolean false can also be returned from the
43-
* critical code callback to indicate that processing did not occure or has
44-
* failed. It is up to the user to decide the last point.
37+
* Executes a block of code only after the check callback passes
38+
* before and after acquiring a lock.
4539
*
4640
* @template T
4741
*
48-
* @param callable(): T $code The critical code callback
42+
* @param callable(): T $code
4943
*
5044
* @return T|false False if check did not pass
5145
*

src/Util/Loop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Loop
2323
private bool $looping = false;
2424

2525
/**
26-
* Notifies that this was the last iteration.
26+
* Notify that this was the last iteration.
2727
*/
2828
public function end(): void
2929
{
@@ -35,7 +35,7 @@ public function end(): void
3535
*
3636
* The code has to be designed in a way that it can be repeated without any
3737
* side effects. When execution was successful it should notify that event
38-
* by calling {@link \Malkusch\Lock\Util\Loop::end()}. I.e. the only side
38+
* by calling {@link Loop::end()}. I.e. the only side
3939
* effects of the code may happen after a successful execution.
4040
*
4141
* If the code throws an exception it will stop repeating the execution.

0 commit comments

Comments
 (0)