From: Michael Date: Sun, 4 Jun 2017 07:26:21 +0000 (+0000) Subject: Overhauled "lock" functionality X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=32f61016d368401890443efc861fff0032ac6c42;p=friendica.git Overhauled "lock" functionality --- diff --git a/include/dbstructure.php b/include/dbstructure.php index 441e7be7f7..1801288a45 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1205,7 +1205,7 @@ function db_definition() { "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""), "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), - "created" => array("type" => "datetime", "default" => NULL_DATE), + "pid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), ), "indexes" => array( "PRIMARY" => array("id"), diff --git a/include/lock.php b/include/lock.php deleted file mode 100644 index 64f6319ef1..0000000000 --- a/include/lock.php +++ /dev/null @@ -1,80 +0,0 @@ - $fn_name), array('limit' => 1)); + + if ((dbm::is_result($lock)) AND !$lock['locked']) { + dba::update('locks', array('locked' => true), array('name' => $fn_name)); + $got_lock = true; + } elseif (!dbm::is_result($lock)) { + dbm::insert('locks', array('name' => $fn_name, 'locked' => true)); + $got_lock = true; + } + + dbm::p("UNLOCK TABLES"); + + if (!$got_lock) { + sleep($wait_sec); + } + } while (!$got_lock AND ((time() - $start) < $timeout)); + + logger('lock_function: function ' . $fn_name . ' with blocking = ' . $block . ' got_lock = ' . $got_lock . ' time = ' . (time() - $start), LOGGER_DEBUG); + + return $got_lock; + } + + public static function remove($fn_name) { + dba::update('locks', array('locked' => false), array('name' => $fn_name)); + + logger('unlock_function: released lock for function ' . $fn_name, LOGGER_DEBUG); + + return; + } +}