= ?', $key, DateTimeFormat::utcNow()]); if (DBM::is_result($lock)) { if ($lock['locked']) { // We want to lock something that was already locked by us? So we got the lock. if ($lock['pid'] == getmypid()) { $got_lock = true; $this->markAcquire($key); } } if (!$lock['locked']) { dba::update('locks', ['locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + 300seconds')], ['name' => $key]); $got_lock = true; $this->markAcquire($key); } } else { dba::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + 300seconds')]); $got_lock = true; $this->markAcquire($key); } dba::unlock(); if (!$got_lock && ($timeout > 0)) { usleep(rand(100000, 2000000)); } } while (!$got_lock && ((time() - $start) < $timeout)); return $got_lock; } /** * (@inheritdoc) */ public function releaseLock($key) { dba::delete('locks', ['name' => $key, 'pid' => getmypid()]); $this->markRelease($key); return; } /** * (@inheritdoc) */ public function releaseAll() { dba::delete('locks', ['pid' => getmypid()]); $this->acquiredLocks = []; } /** * (@inheritdoc) */ public function isLocked($key) { $lock = dba::selectFirst('locks', ['locked'], ['`name` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]); if (DBM::is_result($lock)) { return $lock['locked'] !== false; } else { return false; } } }