Skip to content

Commit 96cd2d8

Browse files
author
Willem Stuursma
committed
Fix various typos and small code style changes
1 parent ff25973 commit 96cd2d8

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

classes/mutex/CASMutex.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public function __construct($timeout = 3)
3939
}
4040

4141
/**
42-
* Notifies the Mutex about a successfull CAS operation.
42+
* Notifies the Mutex about a successful CAS operation.
4343
*/
4444
public function notify()
4545
{
4646
$this->loop->end();
4747
}
4848

4949
/**
50-
* Repeats executing a code until a compare-and-swap operation was succesful.
50+
* Repeats executing a code until a compare-and-swap operation was successful.
5151
*
5252
* The code has to be designed in a way that it can be repeated without any
5353
* side effects. When the CAS operation was successful it should notify

classes/mutex/FlockMutex.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class FlockMutex extends LockMutex
5656
* Sets the file handle.
5757
*
5858
* @param resource $fileHandle The file handle.
59-
* @throws \InvalidArgumentException The file handle is not a valid resource.
59+
* @param int $timeout
6060
*/
6161
public function __construct($fileHandle, $timeout = self::INFINITE_TIMEOUT)
6262
{
@@ -131,8 +131,8 @@ private function lockBusy()
131131
*/
132132
private function acquireNonBlockingLock()
133133
{
134-
if (!flock($this->fileHandle, LOCK_EX | LOCK_NB, $wouldblock)) {
135-
if ($wouldblock) {
134+
if (!flock($this->fileHandle, LOCK_EX | LOCK_NB, $wouldBlock)) {
135+
if ($wouldBlock) {
136136
/*
137137
* Another process holds the lock.
138138
*/

classes/mutex/Mutex.php

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace malkusch\lock\mutex;
44

5+
use malkusch\lock\exception\ExecutionOutsideLockException;
56
use malkusch\lock\exception\LockAcquireException;
67
use malkusch\lock\exception\LockReleaseException;
78
use malkusch\lock\util\DoubleCheckedLocking;
@@ -32,6 +33,7 @@ abstract class Mutex
3233
* @throws \Exception The execution block threw an exception.
3334
* @throws LockAcquireException The mutex could not be acquired, no further side effects.
3435
* @throws LockReleaseException The mutex could not be released, the code was already executed.
36+
* @throws ExecutionOutsideLockException Some code was executed outside of the lock.
3537
*/
3638
abstract public function synchronized(callable $code);
3739

classes/mutex/RedisMutex.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@ protected function acquire($key, $expire)
106106
if ($isAcquired) {
107107
// 4.
108108
return true;
109-
} else {
110-
// 5.
111-
$this->release($key);
112-
113-
// In addition to RedLock it's an exception if too many servers fail.
114-
if (!$this->isMajority(count($this->redisAPIs) - $errored)) {
115-
assert(!is_null($exception)); // The last exception for some context.
116-
throw new LockAcquireException(
117-
"It's not possible to acquire a lock because at least half of the Redis server are not available.",
118-
LockAcquireException::REDIS_NOT_ENOUGH_SERVERS,
119-
$exception
120-
);
121-
}
109+
}
122110

123-
return false;
111+
// 5.
112+
$this->release($key);
113+
114+
// In addition to RedLock it's an exception if too many servers fail.
115+
if (!$this->isMajority(count($this->redisAPIs) - $errored)) {
116+
assert(!is_null($exception)); // The last exception for some context.
117+
throw new LockAcquireException(
118+
"It's not possible to acquire a lock because at least half of the Redis server are not available.",
119+
LockAcquireException::REDIS_NOT_ENOUGH_SERVERS,
120+
$exception
121+
);
124122
}
123+
124+
return false;
125125
}
126126

127127
/**
@@ -193,7 +193,7 @@ abstract protected function add($redisAPI, $key, $value, $expire);
193193
/**
194194
* @param mixed $redisAPI The connected Redis API.
195195
* @param string $script The Lua script.
196-
* @param int $numkeys The number of arguments that represent Redis key names.
196+
* @param int $numkeys The number of values in $arguments that represent Redis key names.
197197
* @param array $arguments Keys and values.
198198
*
199199
* @return mixed The script result, or false if executing failed.

classes/util/Loop.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function end()
6868
public function execute(callable $code)
6969
{
7070
$this->looping = true;
71+
7172
$minWait = 100; // microseconds
7273
$deadline = microtime(true) + $this->timeout; // At this time, the lock will time out.
7374
$result = null;
@@ -78,8 +79,8 @@ public function execute(callable $code)
7879
break;
7980
}
8081

81-
$min = (int) $minWait * 1.5 ** $i;
82-
$max = $min * 2;
82+
$min = (int) $minWait * 1.5 ** $i;
83+
$max = $min * 2;
8384

8485
/*
8586
* Calculate max time remaining, don't sleep any longer than that.

0 commit comments

Comments
 (0)