| 59 | } |
| 60 | |
| 61 | void mir::RecursiveReadWriteMutex::write_lock() |
| 62 | { |
| 63 | auto const my_id = std::this_thread::get_id(); |
| 64 | |
| 65 | std::unique_lock lock{mutex}; |
| 66 | cv.wait(lock, [&] |
| 67 | { |
| 68 | if (write_locking_thread.count && |
| 69 | write_locking_thread.id != my_id) return false; |
| 70 | for (auto const& candidate : read_locking_threads) |
| 71 | { |
| 72 | if (candidate.id != my_id && candidate.count != 0) return false; |
| 73 | } |
| 74 | return true; |
| 75 | }); |
| 76 | |
| 77 | ++write_locking_thread.count; |
| 78 | write_locking_thread.id = my_id; |
| 79 | } |
| 80 | |
| 81 | void mir::RecursiveReadWriteMutex::write_unlock() |
| 82 | { |