| 26 | } |
| 27 | |
| 28 | void ToggleQueue::lock() { |
| 29 | auto holding_thread = std::thread::id(); |
| 30 | auto current_thread = std::this_thread::get_id(); |
| 31 | |
| 32 | while (!m_holder.compare_exchange_weak(holding_thread, current_thread, |
| 33 | std::memory_order_acquire)) { |
| 34 | // In case the current thread is holding the lock, we can just try |
| 35 | // again, checking if this is still true and in case continue |
| 36 | if (holding_thread != current_thread) |
| 37 | holding_thread = std::thread::id(); |
| 38 | } |
| 39 | |
| 40 | m_holder_ref_count++; |
| 41 | } |
| 42 | |
| 43 | void ToggleQueue::maybe_unlock() { |
| 44 | g_assert(owns_lock() && "Nothing to unlock here"); |