1 | <?php |
||
17 | class Semaphore implements LockInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var |
||
21 | */ |
||
22 | private $lock_id; |
||
23 | /** |
||
24 | * @var bool |
||
25 | */ |
||
26 | private $locked = false; |
||
27 | |||
28 | /** |
||
29 | * init a lock |
||
30 | * |
||
31 | * @param $key |
||
32 | * @param $count |
||
33 | * @throws \RuntimeException |
||
34 | */ |
||
35 | 10 | private function __construct($key, $count = 1) |
|
41 | |||
42 | /** |
||
43 | * Semaphore requires a numeric value as the key |
||
44 | * |
||
45 | * @param $identifier |
||
46 | * @return int |
||
47 | */ |
||
48 | 10 | protected function _stringToSemKey($identifier) |
|
57 | |||
58 | /** |
||
59 | * create a lock instance |
||
60 | * |
||
61 | * @param $key |
||
62 | * @return Semaphore |
||
63 | */ |
||
64 | 10 | public static function create($key) |
|
68 | |||
69 | /** |
||
70 | * release lock |
||
71 | * |
||
72 | * @throws \RuntimeException |
||
73 | */ |
||
74 | 10 | public function __destruct() |
|
80 | |||
81 | /** |
||
82 | * is locked |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | 10 | public function isLocked() |
|
90 | |||
91 | /** |
||
92 | * release lock |
||
93 | * |
||
94 | * @return bool |
||
95 | * @throws \RuntimeException |
||
96 | */ |
||
97 | 10 | public function release() |
|
110 | |||
111 | /** |
||
112 | * get a lock |
||
113 | * |
||
114 | * @param bool $blocking |
||
115 | * @return bool |
||
116 | */ |
||
117 | 7 | public function acquire($blocking = true) |
|
142 | } |