* @brief 释放锁 * @return Expected 成功返回空值,失败返回错误 */
| 64 | * @return Expected<void> 成功返回空值,失败返回错误 |
| 65 | */ |
| 66 | [[nodiscard]] __always_inline auto UnLock() -> Expected<void> { |
| 67 | if (!IsLockedByCurrentCore()) { |
| 68 | // klog::Err("spinlock {}: {} unlock by non-owner detected.", |
| 69 | // cpu_io::GetCurrentCoreId(), name); |
| 70 | return std::unexpected(Error{ErrorCode::kSpinLockNotOwned}); |
| 71 | } |
| 72 | |
| 73 | // 先重置 core_id_,再释放锁 |
| 74 | core_id_.store(std::numeric_limits<size_t>::max(), |
| 75 | std::memory_order_release); |
| 76 | locked_.clear(std::memory_order_release); |
| 77 | |
| 78 | if (saved_intr_enable_) { |
| 79 | cpu_io::EnableInterrupt(); |
| 80 | } |
| 81 | return {}; |
| 82 | } |
| 83 | |
| 84 | /// @name 构造/析构函数 |
| 85 | /// @{ |
no test coverage detected