MCPcopy Create free account
hub / github.com/David-Haim/concurrencpp / try_lock

Method try_lock

source/threads/async_lock.cpp:99–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99concurrencpp::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
121void async_lock::unlock() {
122 std::unique_lock<std::mutex> lock(m_awaiter_lock);

Calls 1

unlockMethod · 0.80