]> git.mxchange.org Git - friendica.git/blob - src/Core/Lock.php
Add user contact data superseding to Mastodon\Account::create
[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\Core\Cache\Cache;
11 use Friendica\DI;
12
13 /**
14  * This class contain Functions for preventing parallel execution of functions
15  */
16 class Lock
17 {
18         /**
19          * @brief Acquires a lock for a given name
20          *
21          * @param string  $key     Name of the lock
22          * @param integer $timeout Seconds until we give up
23          * @param integer $ttl     The Lock lifespan, must be one of the Cache constants
24          *
25          * @return boolean Was the lock successful?
26          * @throws \Exception
27          */
28         public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
29         {
30                 return DI::lock()->acquireLock($key, $timeout, $ttl);
31         }
32
33         /**
34          * @brief Releases a lock if it was set by us
35          *
36          * @param string $key      Name of the lock
37          * @param bool   $override Overrides the lock to get releases
38          *
39          * @return bool
40          * @throws \Exception
41          */
42         public static function release($key, $override = false)
43         {
44                 return DI::lock()->releaseLock($key, $override);
45         }
46
47         /**
48          * @brief Releases all lock that were set by us
49          * @return void
50          * @throws \Exception
51          */
52         public static function releaseAll()
53         {
54                 DI::lock()->releaseAll();
55         }
56 }