]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Lock/SemaphoreLockDriver.php
Merge pull request #6955 from tobiasd/20190331-vier
[friendica.git] / src / Core / Lock / SemaphoreLockDriver.php
index b4439743c85fcee74b2a7c54a1cfac8ef7c3219c..781e110b1708a83633d1497296448ba639632595 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Friendica\Core\Lock;
 
+use Friendica\Core\Cache;
+
 class SemaphoreLockDriver extends AbstractLockDriver
 {
        private static $semaphore = [];
@@ -14,17 +16,13 @@ class SemaphoreLockDriver extends AbstractLockDriver
        }
 
        /**
-        * @brief Creates a semaphore key
-        *
-        * @param string $key Name of the lock
-        *
-        * @return integer the semaphore key
+        * (@inheritdoc)
         */
        private static function semaphoreKey($key)
        {
                $temp = get_temppath();
 
-               $file = $temp.'/'.$key.'.sem';
+               $file = $temp . '/' . $key . '.sem';
 
                if (!file_exists($file)) {
                        file_put_contents($file, $key);
@@ -34,15 +32,9 @@ class SemaphoreLockDriver extends AbstractLockDriver
        }
 
        /**
-        *
-        * @brief Sets a lock for a given name
-        *
-        * @param string $key The Name of the lock
-        * @param integer $timeout Seconds until we give up
-        *
-        * @return boolean Was the lock successful?
+        * (@inheritdoc)
         */
-       public function acquireLock($key, $timeout = 120)
+       public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
        {
                self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
                if (self::$semaphore[$key]) {
@@ -56,13 +48,9 @@ class SemaphoreLockDriver extends AbstractLockDriver
        }
 
        /**
-        * @brief Removes a lock if it was set by us
-        *
-        * @param string $key Name of the lock
-        *
-        * @return mixed
+        * (@inheritdoc)
         */
-       public function releaseLock($key)
+       public function releaseLock($key, $override = false)
        {
                if (empty(self::$semaphore[$key])) {
                        return false;
@@ -75,13 +63,10 @@ class SemaphoreLockDriver extends AbstractLockDriver
        }
 
        /**
-        * @brief Checks, if a key is currently locked to a process
-        *
-        * @param string $key The name of the lock
-        * @return bool
+        * (@inheritdoc)
         */
        public function isLocked($key)
        {
-               return @sem_get(self::$semaphore[$key]) !== false;
+               return isset(self::$semaphore[$key]);
        }
 }