fn drop()

in src/sync/rwlock.rs [302:338]


    fn drop(&mut self) {
        self.inner = None;

        let mut state = self.state.borrow_mut();

        trace!(
            holder = ?state.holder,
            waiting_readers = ?state.waiting_readers,
            waiting_writers = ?state.waiting_writers,
            "releasing Read lock on rwlock {:p}",
            self.state
        );

        match &mut state.holder {
            RwLockHolder::Read(readers) => {
                let was_reader = readers.remove(self.me);
                assert!(was_reader);
                if readers.is_empty() {
                    state.holder = RwLockHolder::None;
                }
            }
            _ => panic!("exiting a reader but rwlock is in the wrong state"),
        }

        if ExecutionState::should_stop() {
            return;
        }

        // Unblock every thread waiting on this lock. The scheduler will choose one of them to win
        // the race to this lock, and that thread will re-block all the losers.
        RwLock::<T>::unblock_waiters(&*state, self.me, RwLockType::Read);

        drop(state);

        // Releasing a lock is a yield point
        thread::switch();
    }