FreeBSD/sys/kern/kern_rangelock.c
/*
 * Recalculate the lock->rl_currdep after an unlock.
 */
Recalculate the lock->rl_currdep after an unlock.
Recalculate the lock - > rl_currdep after an unlock .
static void
rangelock_calc_block(struct rangelock *lock)
{
	struct rl_q_entry *entry, *nextentry, *entry1;
	for (entry = lock->rl_currdep; entry != NULL; entry = nextentry) {
		nextentry = TAILQ_NEXT(entry, rl_q_link);
		if (entry->rl_q_flags & RL_LOCK_READ) {
			for (entry1 = TAILQ_FIRST(&lock->rl_waiters);
			    !(entry1->rl_q_flags & RL_LOCK_READ);
			    entry1 = TAILQ_NEXT(entry1, rl_q_link)) {
				if (ranges_overlap(entry, entry1))
					goto out;
			}
		} else {
			for (entry1 = TAILQ_FIRST(&lock->rl_waiters);
			    entry1 != entry;
			    entry1 = TAILQ_NEXT(entry1, rl_q_link)) {
				if (ranges_overlap(entry, entry1))
					goto out;
			}
			TAILQ_REMOVE(&lock->rl_waiters, entry, rl_q_link);
			TAILQ_INSERT_HEAD(&lock->rl_waiters, entry, rl_q_link);
		}
		entry->rl_q_flags |= RL_LOCK_GRANTED;
		wakeup(entry);
	}
out:
	lock->rl_currdep = entry;
}
static void rangelock_calc_block ( struct rangelock * lock ) { struct rl_q_entry * entry , * nextentry , * entry1 ; for ( entry = lock -> rl_currdep ; entry != NULL ; entry = nextentry ) { nextentry = TAILQ_NEXT ( entry , rl_q_link ) ; if ( entry -> rl_q_flags & RL_LOCK_READ ) { for ( entry1 = TAILQ_FIRST ( & lock -> rl_waiters ) ; ! ( entry1 -> rl_q_flags & RL_LOCK_READ ) ; entry1 = TAILQ_NEXT ( entry1 , rl_q_link ) ) { if ( ranges_overlap ( entry , entry1 ) ) goto out ; } } else { for ( entry1 = TAILQ_FIRST ( & lock -> rl_waiters ) ; entry1 != entry ; entry1 = TAILQ_NEXT ( entry1 , rl_q_link ) ) { if ( ranges_overlap ( entry , entry1 ) ) goto out ; } TAILQ_REMOVE ( & lock -> rl_waiters , entry , rl_q_link ) ; TAILQ_INSERT_HEAD ( & lock -> rl_waiters , entry , rl_q_link ) ; } entry -> rl_q_flags |= RL_LOCK_GRANTED ; wakeup ( entry ) ; } out : lock -> rl_currdep = entry ; }
Recalculate the lock->rl_currdep after an unlock.
Recalculate the lock - > rl_currdep after an unlock .
/* Reads must not overlap with granted writes. */ /* Write must not overlap with any granted locks. */ /* Move grantable write locks to the front. */ /* Grant this lock. */