Skip to content

Commit bbc300c

Browse files
authored
Remove CASMutex class (#67)
1 parent def7699 commit bbc300c

File tree

5 files changed

+48
-199
lines changed

5 files changed

+48
-199
lines changed

README.md

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ if ($newBalance === false) {
127127

128128
### Extracting code result after lock release exception
129129

130-
Mutex implementations based on [`Malkush\Lock\Mutex\LockMutex`][12] will throw
131-
[`Malkusch\Lock\Exception\LockReleaseException`][13] in case of lock release
130+
Mutex implementations based on [`Malkush\Lock\Mutex\LockMutex`][10] will throw
131+
[`Malkusch\Lock\Exception\LockReleaseException`][11] in case of lock release
132132
problem, but the synchronized code block will be already executed at this point.
133133
In order to read the code result (or an exception thrown there),
134134
`LockReleaseException` provides methods to extract it.
@@ -164,7 +164,6 @@ Because the [`Malkusch\Lock\Mutex\Mutex`](#mutex) class is an abstract class,
164164
you can choose from one of the provided implementations or create/extend your
165165
own implementation.
166166

167-
- [`CASMutex`](#casmutex)
168167
- [`FlockMutex`](#flockmutex)
169168
- [`MemcachedMutex`](#memcachedmutex)
170169
- [`PHPRedisMutex`](#phpredismutex)
@@ -174,30 +173,6 @@ own implementation.
174173
- [`MySQLMutex`](#mysqlmutex)
175174
- [`PgAdvisoryLockMutex`](#pgadvisorylockmutex)
176175

177-
#### CASMutex
178-
179-
The **CASMutex** has to be used with a [Compare-and-swap][10] operation. This
180-
mutex is lock free. It will repeat executing the code until the CAS operation
181-
was successful. The code should therefore notify the mutex by calling
182-
[`Malkusch\Lock\Mutex\CASMutex::notify()`][11].
183-
184-
As the mutex keeps executing the critical code, it must not have any side
185-
effects as long as the CAS operation was not successful.
186-
187-
Example:
188-
189-
```php
190-
$mutex = new CASMutex();
191-
$mutex->synchronized(function () use ($memcached, $mutex, $amount): void {
192-
$balance = $memcached->get('balance', null, $casToken);
193-
$balance -= $amount;
194-
if (!$memcached->cas($casToken, 'balance', $balance)) {
195-
return;
196-
}
197-
$mutex->notify();
198-
});
199-
```
200-
201176
#### FlockMutex
202177

203178
The **FlockMutex** is a lock implementation based on
@@ -406,7 +381,5 @@ This project is free and is licensed under the MIT.
406381
[7]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/Mutex.php#L60
407382
[8]: https://github.com/php-lock/lock/blob/35526aee28/src/util/DoubleCheckedLocking.php#L63
408383
[9]: https://en.wikipedia.org/wiki/Double-checked_locking
409-
[10]: https://en.wikipedia.org/wiki/Compare-and-swap
410-
[11]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/CASMutex.php#L42
411-
[12]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/LockMutex.php
412-
[13]: https://github.com/php-lock/lock/blob/35526aee28/src/exception/LockReleaseException.php
384+
[10]: https://github.com/php-lock/lock/blob/35526aee28/src/mutex/LockMutex.php
385+
[11]: https://github.com/php-lock/lock/blob/35526aee28/src/exception/LockReleaseException.php

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"redlock",
1313
"memcache",
1414
"redis",
15-
"cas",
1615
"advisory-locks",
1716
"mysql",
1817
"postgresql"

src/Mutex/CASMutex.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/Mutex/CASMutexTest.php

Lines changed: 0 additions & 92 deletions
This file was deleted.

tests/Mutex/FixCiTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Malkusch\Lock\Tests\Mutex;
6+
7+
use phpmock\environment\SleepEnvironmentBuilder;
8+
use phpmock\MockEnabledException;
9+
use phpmock\phpunit\PHPMock;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* This class is currently needed to pass the tests in CI.
14+
*
15+
* I do not know why yet. TODO remove it asap.
16+
*/
17+
class FixCiTest extends TestCase
18+
{
19+
use PHPMock;
20+
21+
#[\Override]
22+
protected function setUp(): void
23+
{
24+
parent::setUp();
25+
26+
$sleepBuilder = new SleepEnvironmentBuilder();
27+
$sleepBuilder->addNamespace(__NAMESPACE__);
28+
$sleepBuilder->addNamespace('Malkusch\Lock\Mutex');
29+
$sleepBuilder->addNamespace('Malkusch\Lock\Util');
30+
$sleep = $sleepBuilder->build();
31+
try {
32+
$sleep->enable();
33+
$this->registerForTearDown($sleep);
34+
} catch (MockEnabledException $e) {
35+
// workaround for burn testing
36+
\assert($e->getMessage() === 'microtime is already enabled.Call disable() on the existing mock.');
37+
}
38+
}
39+
40+
public function testDummy(): void
41+
{
42+
self::assertTrue(microtime(true) > 1.0);
43+
}
44+
}

0 commit comments

Comments
 (0)