/**
* 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
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;
}
}
} while (!$got_lock && ((time() - $start) < $timeout));
+ $this->markAcquire($key);
+
return $got_lock;
}
*/
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;
}
*/
public function releaseAll()
{
- dba::update('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]);
+ dba::delete('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]);
+
+ $this->acquiredLocks = [];
}
}