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(); }
pthread_t _pq_first(pq_queue_t *pq) { pq_list_t *pql; pthread_t pthread = NULL; /* * Make some assertions when debugging is enabled: */ _PQ_ASSERT_INACTIVE("_pq_first: pq_active"); _PQ_SET_ACTIVE(); while (((pql = TAILQ_FIRST(&pq->pq_queue)) != NULL) && (pthread == NULL)) { if ((pthread = TAILQ_FIRST(&pql->pl_head)) == NULL) { /* * The priority list is empty; remove the list * from the queue. */ TAILQ_REMOVE(&pq->pq_queue, pql, pl_link); /* Mark the list as not being in the queue: */ pql->pl_queued = 0; } } _PQ_CLEAR_ACTIVE(); return (pthread); }
void _pq_remove(pq_queue_t *pq, pthread_t pthread) { int prio = pthread->active_priority; /* * Make some assertions when debugging is enabled: */ _PQ_ASSERT_INACTIVE("_pq_remove: pq_active"); _PQ_SET_ACTIVE(); _PQ_ASSERT_IN_PRIOQ(pthread, "_pq_remove: Not in priority queue"); /* * Remove this thread from priority list. Note that if * the priority list becomes empty, it is not removed * from the priority queue because another thread may be * added to the priority list (resulting in a needless * removal/insertion). Priority lists are only removed * from the priority queue when _pq_first is called. */ TAILQ_REMOVE(&pq->pq_lists[prio].pl_head, pthread, pqe); /* This thread is now longer in the priority queue. */ pthread->flags &= ~PTHREAD_FLAGS_IN_PRIOQ; _PQ_CLEAR_ACTIVE(); }
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(); } }
void _waitq_remove(pthread_t pthread) { /* * Make some assertions when debugging is enabled: */ _PQ_ASSERT_INACTIVE("_waitq_remove: pq_active"); _PQ_SET_ACTIVE(); _PQ_ASSERT_IN_WAITQ(pthread, "_waitq_remove: Not in queue"); TAILQ_REMOVE(&_waitingq, pthread, pqe); pthread->flags &= ~PTHREAD_FLAGS_IN_WAITQ; _PQ_CLEAR_ACTIVE(); }
pthread_t _pq_first(pq_queue_t *pq) { pq_list_t *pql; pthread_t pthread = NULL; /* * Make some assertions when debugging is enabled: */ _PQ_ASSERT_INACTIVE("_pq_first: pq_active"); _PQ_SET_ACTIVE(); _PQ_ASSERT_PROTECTED("_pq_first: prioq not protected!"); while (((pql = TAILQ_FIRST(&pq->pq_queue)) != NULL) && (pthread == NULL)) { if ((pthread = TAILQ_FIRST(&pql->pl_head)) == NULL) { /* * The priority list is empty; remove the list * from the queue. */ TAILQ_REMOVE(&pq->pq_queue, pql, pl_link); /* Mark the list as not being in the queue: */ pql->pl_queued = 0; } else if ((pthread->flags & PTHREAD_FLAGS_SUSPENDED) != 0) { /* * This thread is suspended; remove it from the * list and ensure its state is suspended. */ TAILQ_REMOVE(&pql->pl_head, pthread, pqe); PTHREAD_SET_STATE(pthread, PS_SUSPENDED); /* This thread is now longer in the priority queue. */ pthread->flags &= ~PTHREAD_FLAGS_IN_PRIOQ; pthread = NULL; } } _PQ_CLEAR_ACTIVE(); return (pthread); }
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(); }
void _waitq_setactive(void) { _PQ_ASSERT_INACTIVE("_waitq_setactive: pq_active"); _PQ_SET_ACTIVE(); }