public function __construct(Connection
$database) { // __destruct() is causing problems with garbage collections, register a
// shutdown function instead.
drupal_register_shutdown_function([$this, 'releaseAll'
]);
$this->database =
$database;
} /**
* {@inheritdoc}
*/
public function acquire($name,
$timeout = 30.0
) { $name =
$this->
normalizeName($name);
// Insure that the timeout is at least 1 ms.
$timeout =
max($timeout, 0.001
);
$expire =
microtime(TRUE
) +
$timeout;
if (isset($this->locks
[$name])) { // Try to extend the expiration of a lock we already acquired.
$success =
(bool) $this->database->
update('semaphore'
) ->
fields(['expire' =>
$expire]) ->
condition('name',
$name) ->
condition('value',
$this->
getLockId()) ->
execute();