FreeBSD/sys/kern/kern_rangelock.c
/*
 * Add the lock request to the queue of the pending requests for
 * rangelock.  Sleep until the request can be granted.
 */
Add the lock request to the queue of the pending requests for
rangelock.  Sleep until the request can be granted.
Add the lock request to the queue of the pending requests for rangelock . Sleep until the request can be granted .
static void *
rangelock_enqueue(struct rangelock *lock, off_t start, off_t end, int mode,
    struct mtx *ilk)
{
	struct rl_q_entry *entry;
	struct thread *td;
	MPASS(lock != NULL && ilk != NULL);
	td = curthread;
	if (td->td_rlqe != NULL) {
		entry = td->td_rlqe;
		td->td_rlqe = NULL;
	} else
		entry = rlqentry_alloc();
	MPASS(entry != NULL);
	entry->rl_q_flags = mode;
	entry->rl_q_start = start;
	entry->rl_q_end = end;
	mtx_lock(ilk);
	TAILQ_INSERT_TAIL(&lock->rl_waiters, entry, rl_q_link);
	if (lock->rl_currdep == NULL)
		lock->rl_currdep = entry;
	rangelock_calc_block(lock);
	while (!(entry->rl_q_flags & RL_LOCK_GRANTED))
		msleep(entry, ilk, 0, "range", 0);
	mtx_unlock(ilk);
	return (entry);
}
static void * rangelock_enqueue ( struct rangelock * lock , off_t start , off_t end , int mode , struct mtx * ilk ) { struct rl_q_entry * entry ; struct thread * td ; MPASS ( lock != NULL && ilk != NULL ) ; td = curthread ; if ( td -> td_rlqe != NULL ) { entry = td -> td_rlqe ; td -> td_rlqe = NULL ; } else entry = rlqentry_alloc ( ) ; MPASS ( entry != NULL ) ; entry -> rl_q_flags = mode ; entry -> rl_q_start = start ; entry -> rl_q_end = end ; mtx_lock ( ilk ) ; TAILQ_INSERT_TAIL ( & lock -> rl_waiters , entry , rl_q_link ) ; if ( lock -> rl_currdep == NULL ) lock -> rl_currdep = entry ; rangelock_calc_block ( lock ) ; while ( ! ( entry -> rl_q_flags & RL_LOCK_GRANTED ) ) msleep ( entry , ilk , 0 , " " , 0 ) ; mtx_unlock ( ilk ) ; return ( entry ) ; }
Add the lock request to the queue of the pending requests for
 rangelock.
Add the lock request to the queue of the pending requests for rangelock .
/*
	 * XXXKIB TODO. Check that a thread does not try to enqueue a
	 * lock that is incompatible with another request from the same
	 * thread.
	 */