@@ 97-109 (lines=13) @@ | ||
94 | * @return bool |
|
95 | * @throws \RuntimeException |
|
96 | */ |
|
97 | public function release() |
|
98 | { |
|
99 | if (!$this->locked) { |
|
100 | throw new \RuntimeException("release a non lock"); |
|
101 | } |
|
102 | ||
103 | if (!sem_release($this->lock_id)) { |
|
104 | return false; |
|
105 | } |
|
106 | $this->locked = false; |
|
107 | ||
108 | return true; |
|
109 | } |
|
110 | ||
111 | /** |
|
112 | * get a lock |
|
@@ 148-162 (lines=15) @@ | ||
145 | * |
|
146 | * @return bool |
|
147 | */ |
|
148 | public function remove() |
|
149 | { |
|
150 | if ($this->locked) { |
|
151 | throw new \RuntimeException('can not remove a locked semaphore resource'); |
|
152 | } |
|
153 | if (!is_resource($this->lock_id)) { |
|
154 | throw new \RuntimeException('can not remove a empty semaphore resource'); |
|
155 | } |
|
156 | ||
157 | if (!sem_release($this->lock_id)) { |
|
158 | return false; |
|
159 | } |
|
160 | ||
161 | return true; |
|
162 | } |
|
163 | } |