X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FLock%2FDatabaseLockDriver.php;h=9b415753fceecec0663900c682a2e8d5618b1539;hb=ad5ee75159f86010ad0acdf3475eb49f3b9f1192;hp=8761a1479ee219ca24c86cace4481bc240fbe7d0;hpb=0218d16335cd4b873c3edd59fbcc110306d87e71;p=friendica.git diff --git a/src/Core/Lock/DatabaseLockDriver.php b/src/Core/Lock/DatabaseLockDriver.php index 8761a1479e..9b415753fc 100644 --- a/src/Core/Lock/DatabaseLockDriver.php +++ b/src/Core/Lock/DatabaseLockDriver.php @@ -8,7 +8,7 @@ use Friendica\Database\DBM; /** * Locking driver that stores the locks in the database */ -class DatabaseLockDriver implements ILockDriver +class DatabaseLockDriver extends AbstractLockDriver { /** * @brief Sets a lock for a given name @@ -42,7 +42,7 @@ class DatabaseLockDriver implements ILockDriver dba::update('locks', ['locked' => true, 'pid' => getmypid()], ['name' => $key]); $got_lock = true; } - } elseif (!DBM::is_result($lock)) { + } else { dba::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid()]); $got_lock = true; } @@ -54,6 +54,8 @@ class DatabaseLockDriver implements ILockDriver } } while (!$got_lock && ((time() - $start) < $timeout)); + $this->markAcquire($key); + return $got_lock; } @@ -66,7 +68,9 @@ class DatabaseLockDriver implements ILockDriver */ public function releaseLock($key) { - dba::update('locks', ['locked' => false, 'pid' => 0], ['name' => $key, 'pid' => getmypid()]); + dba::delete('locks', ['locked' => false, 'pid' => 0], ['name' => $key, 'pid' => getmypid()]); + + $this->releaseLock($key); return; } @@ -78,6 +82,8 @@ class DatabaseLockDriver implements ILockDriver */ public function releaseAll() { - dba::update('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]); + dba::delete('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]); + + $this->acquiredLocks = []; } }