-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coroutines): added global exclusive single coroutine access to ea…
…ch container operation, so no deadlocks occurence is possible
- Loading branch information
Rastusik
committed
Feb 6, 2023
1 parent
80d2c60
commit 6d0611b
Showing
10 changed files
with
189 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Bridge/Symfony/Container/ContainerSourceCodeExtractor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Bridge\Symfony\Container; | ||
|
||
use ZEngine\Reflection\ReflectionMethod; | ||
|
||
final class ContainerSourceCodeExtractor | ||
{ | ||
private array $sourceCode; | ||
|
||
public function __construct(string $sourceCode) | ||
{ | ||
$this->sourceCode = explode(PHP_EOL, $sourceCode); | ||
} | ||
|
||
public function getContainerInternalsForMethod(ReflectionMethod $method): array | ||
{ | ||
$code = $this->getMethodCode($method); | ||
|
||
if (!preg_match( | ||
'/return \\$this->(?P<type>[a-z]+)\[\'(?P<key>[^\']+)\'\](\[\'(?P<key2>[^\']+)\'\])? \=/', | ||
$code, | ||
$matches | ||
)) { | ||
return []; | ||
} | ||
|
||
return $matches; | ||
} | ||
|
||
public function getMethodCode(ReflectionMethod $method): string | ||
{ | ||
$startLine = $method->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block | ||
$endLine = $method->getEndLine(); | ||
$length = $endLine - $startLine; | ||
|
||
return implode(PHP_EOL, array_slice($this->sourceCode, $startLine, $length)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Component\Locking; | ||
|
||
final class ContainerLocking extends CoroutineLocking | ||
{ | ||
private const LOCK_KEY = 'EXCLUSIVE_CONTAINER_LOCK'; | ||
|
||
public function acquire(string $key): Lock | ||
{ | ||
throw new \RuntimeException('This lock is not supposed to have variable lock keys.'); | ||
} | ||
|
||
public function acquireContainerLock(): Lock | ||
{ | ||
return parent::acquire(self::LOCK_KEY); | ||
} | ||
|
||
public static function init(?Locking $locking = null): Locking | ||
{ | ||
if (null === $locking) { | ||
$locking = new ContainerLocking(); | ||
} | ||
|
||
return $locking; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.