summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_priority_queue.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2002-05-24 04:32:28 +0000
committerdeischen <deischen@FreeBSD.org>2002-05-24 04:32:28 +0000
commit9ba1f9fa381dcbfb861533fdda13f9f27da78f14 (patch)
tree15691e04d3960954bb9843fcfd9d5beaf2553f80 /lib/libpthread/thread/thr_priority_queue.c
parentabd4f3d6cc97e6f9042d207b7f1442f11860e88d (diff)
downloadFreeBSD-src-9ba1f9fa381dcbfb861533fdda13f9f27da78f14.zip
FreeBSD-src-9ba1f9fa381dcbfb861533fdda13f9f27da78f14.tar.gz
Revamp suspend and resume. While I'm here add pthread_suspend_all_np()
and pthread_resume_all_np(). These suspend and resume all threads except the current thread, respectively. The existing functions pthread_single_np() and pthread_multi_np(), which formerly had no effect, now exhibit the same behaviour and pthread_suspend_all_np() and pthread_resume_all_np(). These functions have been added mostly for the native java port. Don't allow the uthread kernel pipe to use the same descriptors as stdio. Mostily submitted by Oswald Buddenhagen <ossi@kde.org>. Correct some minor style nits.
Diffstat (limited to 'lib/libpthread/thread/thr_priority_queue.c')
-rw-r--r--lib/libpthread/thread/thr_priority_queue.c97
1 files changed, 65 insertions, 32 deletions
diff --git a/lib/libpthread/thread/thr_priority_queue.c b/lib/libpthread/thread/thr_priority_queue.c
index 55d742b..b700d97 100644
--- a/lib/libpthread/thread/thr_priority_queue.c
+++ b/lib/libpthread/thread/thr_priority_queue.c
@@ -164,52 +164,74 @@ _pq_remove(pq_queue_t *pq, pthread_t pthread)
void
_pq_insert_head(pq_queue_t *pq, pthread_t pthread)
{
- int prio = pthread->active_priority;
+ int prio;
/*
- * Make some assertions when debugging is enabled:
+ * Don't insert suspended threads into the priority queue.
+ * The caller is responsible for setting the threads state.
*/
- _PQ_ASSERT_INACTIVE("_pq_insert_head: pq_active");
- _PQ_SET_ACTIVE();
- _PQ_ASSERT_NOT_QUEUED(pthread,
- "_pq_insert_head: Already in priority queue");
- _PQ_ASSERT_PROTECTED("_pq_insert_head: prioq not protected!");
-
- TAILQ_INSERT_HEAD(&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;
+ 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_head: pq_active");
+ _PQ_SET_ACTIVE();
+ _PQ_ASSERT_NOT_QUEUED(pthread,
+ "_pq_insert_head: Already in priority queue");
+ _PQ_ASSERT_PROTECTED("_pq_insert_head: prioq not protected!");
+
+ prio = pthread->active_priority;
+ TAILQ_INSERT_HEAD(&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();
+ _PQ_CLEAR_ACTIVE();
+ }
}
void
_pq_insert_tail(pq_queue_t *pq, pthread_t pthread)
{
- int prio = pthread->active_priority;
+ int prio;
/*
- * Make some assertions when debugging is enabled:
+ * Don't insert suspended threads into the priority queue.
+ * The caller is responsible for setting the threads state.
*/
- _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!");
-
- 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;
+ 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();
+ _PQ_CLEAR_ACTIVE();
+ }
}
@@ -237,6 +259,17 @@ _pq_first(pq_queue_t *pq)
/* 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;
}
}
OpenPOWER on IntegriCloud