| 12 | } |
| 13 | |
| 14 | void ReadWriteLock::AquireReadLock() { |
| 15 | //wait till there are no waiting writers and increment active readers |
| 16 | std::unique_lock<std::mutex> lk(shared); |
| 17 | while ( waiting_writers != 0 ) { //starving readers and giving writer priority |
| 18 | reader_gate.wait(lk); |
| 19 | } |
| 20 | active_readers++; |
| 21 | lk.unlock(); |
| 22 | } |
| 23 | |
| 24 | void ReadWriteLock::ReleaseReadUnlock() { |
| 25 | //get lock decrement active readers and notify one waiting writer |