pthread_mutex_lock(&rsq->mutex);while((qe=TAILQ_FIRST(&rsq->queue_head))==NULL){if(rscount<NCPU){/*
* special case for first one.
*
* We use the statically allocated state
* to make sure that we have at least one
* available state.
*/if(rscount==0)qe=&rs0;elseqe=newrstate;if(qe!=NULL){rscount++;break;}}/* All (NCPU) states are in use, sleep and wait for a wakeup */pthread_cond_wait(&rsq->cv_queue,&rsq->mutex);}/* assert(qe != NULL); *//*
* If the queue is not empty, we must got the state from
* there, and the state has to be removed from the queue.
*/if(!TAILQ_EMPTY(&rsq->queue_head))TAILQ_REMOVE(&rsq->queue_head,qe,entries);pthread_mutex_unlock(&rsq->mutex);return(qe);