summaryrefslogtreecommitdiff
path: root/vendor/symfony/cache/LockRegistry.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/cache/LockRegistry.php')
-rw-r--r--vendor/symfony/cache/LockRegistry.php19
1 files changed, 15 insertions, 4 deletions
diff --git a/vendor/symfony/cache/LockRegistry.php b/vendor/symfony/cache/LockRegistry.php
index e0318e900c..ef49805ea0 100644
--- a/vendor/symfony/cache/LockRegistry.php
+++ b/vendor/symfony/cache/LockRegistry.php
@@ -23,7 +23,7 @@ use Symfony\Contracts\Cache\ItemInterface;
*
* @author Nicolas Grekas <p@tchwork.com>
*/
-class LockRegistry
+final class LockRegistry
{
private static $openedFiles = [];
private static $lockedFiles = [];
@@ -74,7 +74,7 @@ class LockRegistry
return $previousFiles;
}
- public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool)
+ public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata = null)
{
$key = self::$files ? crc32($item->getKey()) % \count(self::$files) : -1;
@@ -88,7 +88,18 @@ class LockRegistry
if (flock($lock, LOCK_EX | LOCK_NB)) {
self::$lockedFiles[$key] = true;
- return $callback($item, $save);
+ $value = $callback($item, $save);
+
+ if ($save) {
+ if ($setMetadata) {
+ $setMetadata($item);
+ }
+
+ $pool->save($item->set($value));
+ $save = false;
+ }
+
+ return $value;
}
// if we failed the race, retry locking in blocking mode to wait for the winner
flock($lock, LOCK_SH);
@@ -125,6 +136,6 @@ class LockRegistry
restore_error_handler();
}
- self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
+ return self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
}
}