1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
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. */
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. */
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
)
29 ASSERT(th
->p_nextwaiting
== NULL
);
30 if (q
->tail
== NULL
) {
35 prio
= th
->p_priority
;
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
;
46 /* Priority is no greater than any thread in the queue.
47 Insert at end of queue */
48 q
->tail
->p_nextwaiting
= th
;
52 static inline pthread_descr
dequeue(pthread_queue
* q
)
57 q
->head
= th
->p_nextwaiting
;
58 if (q
->head
== NULL
) q
->tail
= NULL
;
59 th
->p_nextwaiting
= NULL
;