aboutsummaryrefslogtreecommitdiff
path: root/linuxthreads/queue.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-06-25 19:36:00 +0000
committerUlrich Drepper <drepper@redhat.com>1998-06-25 19:36:00 +0000
commit3387a425e65b839b68bd2973f6bc5ab22315cc5d (patch)
tree375713a0b865b10b9eddd9c9877ad68cf0bdc851 /linuxthreads/queue.h
parentd47aac39992cb1dd705d8c584f4d3979d7ce4602 (diff)
downloadglibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar.gz
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar.bz2
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.zip
Finish user stack support. Change locking code to be safe in situations with different priorities.
1998-06-25 19:27 Ulrich Drepper <drepper@cygnus.com> * attr.c: Finish user stack support. Change locking code to be safe in situations with different priorities. * cancel.c: Likewise. * condvar.c: Likewise. * internals.h: Likewise. * join.c: Likewise. * manager.c: Likewise. * mutex.c: Likewise. * pthread.c: Likewise. * ptlongjmp.c: Likewise. * queue.h: Likewise. * rwlock.c: Likewise. * semaphore.c: Likewise. * semaphore.h: Likewise. * signals.c: Likewise. * spinlock.c: Likewise. * spinlock.h: Likewise. Patches by Xavier leroy. 1998-06-25 Ulrich Drepper <drepper@cygnus.com> * sysdeps/pthread/pthread.h: Make [sg]et_stacksize and [sg]et_stackaddr prototypes always available. * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define _POSIX_THREAD_ATTR_STACKSIZE and _POSIX_THREAD_ATTR_STACKADDR.
Diffstat (limited to 'linuxthreads/queue.h')
-rw-r--r--linuxthreads/queue.h57
1 files changed, 25 insertions, 32 deletions
diff --git a/linuxthreads/queue.h b/linuxthreads/queue.h
index 60039cce6e..fa8c5d861d 100644
--- a/linuxthreads/queue.h
+++ b/linuxthreads/queue.h
@@ -14,49 +14,42 @@
/* Waiting queues */
-typedef struct _pthread_queue pthread_queue;
+/* Waiting queues are represented by lists of thread descriptors
+ linked through their p_nextwaiting field. The lists are kept
+ sorted by decreasing priority, and then decreasing waiting time. */
-static inline void queue_init(pthread_queue * q)
+static inline void enqueue(pthread_descr * q, pthread_descr th)
{
- q->head = q->tail = NULL;
-}
-
-static inline void enqueue(pthread_queue * q, pthread_descr th)
-{
- int prio;
- pthread_descr * elt;
-
+ int prio = th->p_priority;
ASSERT(th->p_nextwaiting == NULL);
- if (q->tail == NULL) {
- q->head = th;
- q->tail = th;
- return;
- }
- prio = th->p_priority;
- if (prio > 0) {
- /* Insert in queue according to priority order */
- for (elt = &(q->head); *elt != NULL; elt = &((*elt)->p_nextwaiting)) {
- if (prio > (*elt)->p_priority) {
- th->p_nextwaiting = *elt;
- *elt = th;
- return;
- }
+ for (; *q != NULL; q = &((*q)->p_nextwaiting)) {
+ if (prio > (*q)->p_priority) {
+ th->p_nextwaiting = *q;
+ *q = th;
+ return;
}
}
- /* Priority is no greater than any thread in the queue.
- Insert at end of queue */
- q->tail->p_nextwaiting = th;
- q->tail = th;
+ *q = th;
}
-static inline pthread_descr dequeue(pthread_queue * q)
+static inline pthread_descr dequeue(pthread_descr * q)
{
pthread_descr th;
- th = q->head;
+ th = *q;
if (th != NULL) {
- q->head = th->p_nextwaiting;
- if (q->head == NULL) q->tail = NULL;
+ *q = th->p_nextwaiting;
th->p_nextwaiting = NULL;
}
return th;
}
+
+static inline void remove_from_queue(pthread_descr * q, pthread_descr th)
+{
+ for (; *q != NULL; q = &((*q)->p_nextwaiting)) {
+ if (*q == th) {
+ *q = th->p_nextwaiting;
+ th->p_nextwaiting = NULL;
+ return;
+ }
+ }
+}