X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FLock.php;h=eba264ad932d6ba6357c5fd566cafbc8c7ff8a30;hb=1e9bff88bc05fce154edee9f047e7d8922184140;hp=9bf67d7043b8682e9af46078fe793795d1507fe2;hpb=6189f6c8e76305ae5a29a685e3ec5a418ff92941;p=friendica.git diff --git a/src/Util/Lock.php b/src/Util/Lock.php index 9bf67d7043..eba264ad93 100644 --- a/src/Util/Lock.php +++ b/src/Util/Lock.php @@ -1,30 +1,35 @@ $fn_name), array('limit' => 1)); + $lock = dba::selectFirst('locks', ['locked', 'pid'], ['name' => $fn_name]); - if (Dbm::is_result($lock)) { + if (DBM::is_result($lock)) { if ($lock['locked']) { // When the process id isn't used anymore, we can safely claim the lock for us. if (!posix_kill($lock['pid'], 0)) { @@ -133,11 +140,11 @@ class Lock { } } if (!$lock['locked']) { - dba::update('locks', array('locked' => true, 'pid' => getmypid()), array('name' => $fn_name)); + dba::update('locks', ['locked' => true, 'pid' => getmypid()], ['name' => $fn_name]); $got_lock = true; } - } elseif (!Dbm::is_result($lock)) { - dba::insert('locks', array('name' => $fn_name, 'locked' => true, 'pid' => getmypid())); + } elseif (!DBM::is_result($lock)) { + dba::insert('locks', ['name' => $fn_name, 'locked' => true, 'pid' => getmypid()]); $got_lock = true; } @@ -155,8 +162,10 @@ class Lock { * @brief Removes a lock if it was set by us * * @param string $fn_name Name of the lock + * @return mixed */ - public static function remove($fn_name) { + public static function remove($fn_name) + { if (function_exists('sem_get') && version_compare(PHP_VERSION, '5.6.1', '>=')) { if (empty(self::$semaphore[$fn_name])) { return false; @@ -180,21 +189,23 @@ class Lock { return; } - dba::update('locks', array('locked' => false, 'pid' => 0), array('name' => $fn_name, 'pid' => getmypid())); + dba::update('locks', ['locked' => false, 'pid' => 0], ['name' => $fn_name, 'pid' => getmypid()]); return; } /** * @brief Removes all lock that were set by us + * @return void */ - public static function removeAll() { + public static function removeAll() + { $memcache = self::connectMemcache(); if (is_object($memcache)) { // We cannot delete all cache entries, but this doesn't matter with memcache return; } - dba::update('locks', array('locked' => false, 'pid' => 0), array('pid' => getmypid())); + dba::update('locks', ['locked' => false, 'pid' => 0], ['pid' => getmypid()]); return; } }