From: Michael Date: Sun, 4 Jun 2017 12:59:29 +0000 (+0000) Subject: Database locks are now having its very own functions X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d2cb87a200cadcf055b194ea0b2fc577640fdea2;p=friendica.git Database locks are now having its very own functions --- diff --git a/include/dba.php b/include/dba.php index b9e6c32d56..1fff51f3d1 100644 --- a/include/dba.php +++ b/include/dba.php @@ -806,6 +806,28 @@ class dba { return self::e($sql, $param); } + /** + * @brief Locks a table for exclusive write access + * + * This function can be extended in the future to accept a table array as well. + * + * @param string $table Table name + * + * @return boolean was the lock successful? + */ + static public function lock($table) { + return self::e("LOCK TABLES `".self::$dbo->escape($table)."` WRITE"); + } + + /** + * @brief Unlocks all locked tables + * + * @return boolean was the unlock successful? + */ + static public function unlock() { + return self::e("UNLOCK TABLES"); + } + /** * @brief Starts a transaction * diff --git a/src/Util/Lock.php b/src/Util/Lock.php index e8fa03f784..1a33e819f0 100644 --- a/src/Util/Lock.php +++ b/src/Util/Lock.php @@ -34,7 +34,7 @@ class Lock { $start = time(); do { - dba::p("LOCK TABLE `locks` WRITE"); + dba::lock('locks'); $lock = dba::select('locks', array('locked', 'pid'), array('name' => $fn_name), array('limit' => 1)); if (dbm::is_result($lock)) { @@ -57,7 +57,7 @@ class Lock { $got_lock = true; } - dba::p("UNLOCK TABLES"); + dba::unlock(); if (!$got_lock) { sleep($wait_sec);