MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / ~LockGuard

Method ~LockGuard

src/include/spinlock.hpp:178–209  ·  view source on GitHub ↗

* @brief 析构函数,自动释放锁 */

Source from the content-addressed store, hash-verified

176 * @brief 析构函数,自动释放锁
177 */
178 ~LockGuard() {
179 mutex_.UnLock().or_else([&](auto&& err) {
180 char core_buf[4] = {};
181 auto core_id = cpu_io::GetCurrentCoreId();
182 size_t pos = 0;
183 if (core_id == 0) {
184 core_buf[pos++] = '0';
185 } else {
186 char tmp[4] = {};
187 size_t tmp_pos = 0;
188 while (core_id > 0 && tmp_pos < sizeof(tmp)) {
189 tmp[tmp_pos++] = static_cast<char>('0' + (core_id % 10));
190 core_id /= 10;
191 }
192 while (tmp_pos > 0) {
193 core_buf[pos++] = tmp[--tmp_pos];
194 }
195 }
196 core_buf[pos] = '\0';
197 klog::RawPut("PANIC: LockGuard failed to release lock '");
198 klog::RawPut(mutex_.name);
199 klog::RawPut("' on core ");
200 klog::RawPut(core_buf);
201 klog::RawPut(": ");
202 klog::RawPut(err.message());
203 klog::RawPut("\n");
204 while (true) {
205 cpu_io::Pause();
206 }
207 return Expected<void>{};
208 });
209 }
210
211 LockGuard() = delete;
212 LockGuard(const LockGuard&) = delete;

Callers

nothing calls this directly

Calls 5

GetCurrentCoreIdFunction · 0.85
RawPutFunction · 0.85
PauseFunction · 0.85
messageMethod · 0.80
UnLockMethod · 0.45

Tested by

no test coverage detected