| 97 | } |
| 98 | |
| 99 | concurrencpp::lazy_result<bool> async_lock::try_lock() { |
| 100 | auto res = false; |
| 101 | |
| 102 | std::unique_lock<std::mutex> lock(m_awaiter_lock); |
| 103 | if (!m_locked) { |
| 104 | m_locked = true; |
| 105 | lock.unlock(); |
| 106 | res = true; |
| 107 | } else { |
| 108 | lock.unlock(); |
| 109 | } |
| 110 | |
| 111 | #ifdef CRCPP_DEBUG_MODE |
| 112 | if (res) { |
| 113 | const auto current_count = m_thread_count_in_critical_section.fetch_add(1, std::memory_order_relaxed); |
| 114 | assert(current_count == 0); |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | co_return res; |
| 119 | } |
| 120 | |
| 121 | void async_lock::unlock() { |
| 122 | std::unique_lock<std::mutex> lock(m_awaiter_lock); |