| 119 | } |
| 120 | |
| 121 | void async_lock::unlock() { |
| 122 | std::unique_lock<std::mutex> lock(m_awaiter_lock); |
| 123 | if (!m_locked) { // trying to unlocked non-owned mutex |
| 124 | lock.unlock(); |
| 125 | throw std::system_error(static_cast<int>(std::errc::operation_not_permitted), |
| 126 | std::system_category(), |
| 127 | details::consts::k_async_lock_unlock_invalid_lock_err_msg); |
| 128 | } |
| 129 | |
| 130 | m_locked = false; |
| 131 | |
| 132 | #ifdef CRCPP_DEBUG_MODE |
| 133 | const auto current_count = m_thread_count_in_critical_section.fetch_sub(1, std::memory_order_relaxed); |
| 134 | assert(current_count == 1); |
| 135 | #endif |
| 136 | |
| 137 | const auto awaiter = m_awaiters.pop_front(); |
| 138 | lock.unlock(); |
| 139 | |
| 140 | if (awaiter != nullptr) { |
| 141 | awaiter->retry(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * scoped_async_lock |