| 35 | } |
| 36 | |
| 37 | void acquireWrite(bool exclusive = true) { |
| 38 | std::unique_lock<fastlock> rm(m_readLock, std::defer_lock); |
| 39 | if (m_multi) { |
| 40 | rm.lock(); |
| 41 | m_writeWaiting = true; |
| 42 | while (m_readCount > 0) |
| 43 | m_cv.wait(rm); |
| 44 | if (exclusive) { |
| 45 | /* Another thread might have the write lock while we have the internal lock |
| 46 | but won't be able to release it until they can acquire the internal lock |
| 47 | so release the internal lock and try again instead of waiting to avoid deadlock */ |
| 48 | while(!m_writeLock.try_lock()) |
| 49 | m_cv.wait(rm); |
| 50 | } |
| 51 | } |
| 52 | m_writeCount++; |
| 53 | m_writeWaiting = false; |
| 54 | } |
| 55 | |
| 56 | void upgradeWrite(bool exclusive = true) { |
| 57 | releaseRead(); |
no test coverage detected