Update.
[glibc.git] / linuxthreads / queue.h
blob60039cce6e4fd50156b4ed8e4faab658c0ced342
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU Library General Public License for more details. */
15 /* Waiting queues */
17 typedef struct _pthread_queue pthread_queue;
19 static inline void queue_init(pthread_queue * q)
21 q->head = q->tail = NULL;
24 static inline void enqueue(pthread_queue * q, pthread_descr th)
26 int prio;
27 pthread_descr * elt;
29 ASSERT(th->p_nextwaiting == NULL);
30 if (q->tail == NULL) {
31 q->head = th;
32 q->tail = th;
33 return;
35 prio = th->p_priority;
36 if (prio > 0) {
37 /* Insert in queue according to priority order */
38 for (elt = &(q->head); *elt != NULL; elt = &((*elt)->p_nextwaiting)) {
39 if (prio > (*elt)->p_priority) {
40 th->p_nextwaiting = *elt;
41 *elt = th;
42 return;
46 /* Priority is no greater than any thread in the queue.
47 Insert at end of queue */
48 q->tail->p_nextwaiting = th;
49 q->tail = th;
52 static inline pthread_descr dequeue(pthread_queue * q)
54 pthread_descr th;
55 th = q->head;
56 if (th != NULL) {
57 q->head = th->p_nextwaiting;
58 if (q->head == NULL) q->tail = NULL;
59 th->p_nextwaiting = NULL;
61 return th;