예제 #1
0
void
_waitq_insert(pthread_t pthread)
{
	pthread_t tid;

	/*
	 * Make some assertions when debugging is enabled:
	 */
	_PQ_ASSERT_INACTIVE("_waitq_insert: pq_active");
	_PQ_SET_ACTIVE();
	_PQ_ASSERT_NOT_QUEUED(pthread, "_waitq_insert: Already in queue");

	if (pthread->wakeup_time.tv_sec == -1)
		TAILQ_INSERT_TAIL(&_waitingq, pthread, pqe);
	else {
		tid = TAILQ_FIRST(&_waitingq);
		while ((tid != NULL) && (tid->wakeup_time.tv_sec != -1) && 
		    ((tid->wakeup_time.tv_sec < pthread->wakeup_time.tv_sec) ||
		    ((tid->wakeup_time.tv_sec == pthread->wakeup_time.tv_sec) &&
		    (tid->wakeup_time.tv_nsec <= pthread->wakeup_time.tv_nsec))))
			tid = TAILQ_NEXT(tid, pqe);
		if (tid == NULL)
			TAILQ_INSERT_TAIL(&_waitingq, pthread, pqe);
		else
			TAILQ_INSERT_BEFORE(tid, pthread, pqe);
	}
	pthread->flags |= PTHREAD_FLAGS_IN_WAITQ;

	_PQ_CLEAR_ACTIVE();
}
예제 #2
0
void
_pq_insert_tail(pq_queue_t *pq, pthread_t pthread)
{
	int prio;

	/*
	 * Don't insert suspended threads into the priority queue.
	 * The caller is responsible for setting the threads state.
	 */
	if ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) {
		/* Make sure the threads state is suspended. */
		if (pthread->state != PS_SUSPENDED)
			PTHREAD_SET_STATE(pthread, PS_SUSPENDED);
	} else {
		/*
		 * Make some assertions when debugging is enabled:
		 */
		_PQ_ASSERT_INACTIVE("_pq_insert_tail: pq_active");
		_PQ_SET_ACTIVE();
		_PQ_ASSERT_NOT_QUEUED(pthread,
		    "_pq_insert_tail: Already in priority queue");
		_PQ_ASSERT_PROTECTED("_pq_insert_tail: prioq not protected!");

		prio = pthread->active_priority;
		TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe);
		if (pq->pq_lists[prio].pl_queued == 0)
			/* Insert the list into the priority queue: */
			pq_insert_prio_list(pq, prio);

		/* Mark this thread as being in the priority queue. */
		pthread->flags |= PTHREAD_FLAGS_IN_PRIOQ;

		_PQ_CLEAR_ACTIVE();
	}
}
예제 #3
0
void
_pq_insert_tail(pq_queue_t *pq, pthread_t pthread)
{
	int prio = pthread->active_priority;

	/*
	 * Make some assertions when debugging is enabled:
	 */
	_PQ_ASSERT_INACTIVE("_pq_insert_tail: pq_active");
	_PQ_SET_ACTIVE();
	_PQ_ASSERT_NOT_QUEUED(pthread,
	    "_pq_insert_tail: Already in priority queue");

	TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe);
	if (pq->pq_lists[prio].pl_queued == 0)
		/* Insert the list into the priority queue: */
		pq_insert_prio_list(pq, prio);

	/* Mark this thread as being in the priority queue. */
	pthread->flags |= PTHREAD_FLAGS_IN_PRIOQ;

	_PQ_CLEAR_ACTIVE();
}