]> git.mxchange.org Git - friendica.git/blob - src/Core/Lock.php
Merge pull request #7541 from vinzv/patch-2
[friendica.git] / src / Core / Lock.php
1 <?php
2
3 /**
4  * @file src/Core/Lock.php
5  * @brief Functions for preventing parallel execution of functions
6  */
7
8 namespace Friendica\Core;
9
10 use Friendica\BaseObject;
11 use Friendica\Core\Cache\Cache;
12 use Friendica\Core\Lock\ILock;
13
14 /**
15  * This class contain Functions for preventing parallel execution of functions
16  */
17 class Lock extends BaseObject
18 {
19         /**
20          * @brief Acquires a lock for a given name
21          *
22          * @param string  $key     Name of the lock
23          * @param integer $timeout Seconds until we give up
24          * @param integer $ttl     The Lock lifespan, must be one of the Cache constants
25          *
26          * @return boolean Was the lock successful?
27          * @throws \Exception
28          */
29         public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
30         {
31                 return self::getClass(ILock::class)->acquireLock($key, $timeout, $ttl);
32         }
33
34         /**
35          * @brief Releases a lock if it was set by us
36          *
37          * @param string $key      Name of the lock
38          * @param bool   $override Overrides the lock to get releases
39          *
40          * @return void
41          * @throws \Exception
42          */
43         public static function release($key, $override = false)
44         {
45                 return self::getClass(ILock::class)->releaseLock($key, $override);
46         }
47
48         /**
49          * @brief Releases all lock that were set by us
50          * @return void
51          * @throws \Exception
52          */
53         public static function releaseAll()
54         {
55                 self::getClass(ILock::class)->releaseAll();
56         }
57 }