X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FUtil%2FLock.php;h=66a568811d62c80ee093ff6e3a889915dd95f015;hb=1bce1b57eb296ffbf199d6cfa5a963098e953381;hp=a50faf2d90d8c637cd5252d4974758b80b54f2ec;hpb=2b161108fe6552ef2effb7b300553f0242b2e49e;p=friendica.git diff --git a/src/Util/Lock.php b/src/Util/Lock.php index a50faf2d90..66a568811d 100644 --- a/src/Util/Lock.php +++ b/src/Util/Lock.php @@ -1,30 +1,35 @@ =')) { + self::$semaphore[$fn_name] = sem_get(self::semaphoreKey($fn_name)); if (self::$semaphore[$fn_name]) { return sem_acquire(self::$semaphore[$fn_name], ($timeout == 0)); } @@ -118,9 +126,9 @@ class Lock { do { dba::lock('locks'); - $lock = dba::select('locks', array('locked', 'pid'), array('name' => $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)) { @@ -135,7 +143,7 @@ class Lock { dba::update('locks', array('locked' => true, 'pid' => getmypid()), array('name' => $fn_name)); $got_lock = true; } - } elseif (!dbm::is_result($lock)) { + } elseif (!DBM::is_result($lock)) { dba::insert('locks', array('name' => $fn_name, 'locked' => true, 'pid' => getmypid())); $got_lock = true; } @@ -154,11 +162,18 @@ 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) { - if (function_exists('sem_get') && self::$semaphore[$fn_name]) { - sem_release(self::$semaphore[$fn_name]); - return; + 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; + } else { + $success = @sem_release(self::$semaphore[$fn_name]); + unset(self::$semaphore[$fn_name]); + return $success; + } } $memcache = self::connectMemcache(); @@ -180,8 +195,10 @@ class Lock { /** * @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