Acquire read lock on given mutex.
| 64 | |
| 65 | //! Acquire read lock on given mutex. |
| 66 | void spin_rw_mutex_v3::internal_acquire_reader() |
| 67 | { |
| 68 | ITT_NOTIFY(sync_prepare, this); |
| 69 | for( internal::atomic_backoff b;;b.pause() ){ |
| 70 | state_t s = const_cast<volatile state_t&>(state); // ensure reloading |
| 71 | if( !(s & (WRITER|WRITER_PENDING)) ) { // no writer or write requests |
| 72 | state_t t = (state_t)__TBB_FetchAndAddW( &state, (intptr_t) ONE_READER ); |
| 73 | if( !( t&WRITER )) |
| 74 | break; // successfully stored increased number of readers |
| 75 | // writer got there first, undo the increment |
| 76 | __TBB_FetchAndAddW( &state, -(intptr_t)ONE_READER ); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | ITT_NOTIFY(sync_acquired, this); |
| 81 | __TBB_ASSERT( state & READERS, "invalid state of a read lock: no readers" ); |
| 82 | } |
| 83 | |
| 84 | //! Upgrade reader to become a writer. |
| 85 | /** Returns whether the upgrade happened without releasing and re-acquiring the lock */ |
no test coverage detected