Test for stack alignment.
[glibc.git] / linuxthreads / queue.h
blob28bd75531c24b3680abd56f2263a0bd96b1440e1
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 /* Waiting queues are represented by lists of thread descriptors
18 linked through their p_nextwaiting field. The lists are kept
19 sorted by decreasing priority, and then decreasing waiting time. */
21 static inline void enqueue(pthread_descr * q, pthread_descr th)
23 int prio = th->p_priority;
24 ASSERT(th->p_nextwaiting == NULL);
25 for (; *q != NULL; q = &((*q)->p_nextwaiting)) {
26 if (prio > (*q)->p_priority) {
27 th->p_nextwaiting = *q;
28 *q = th;
29 return;
32 *q = th;
35 static inline pthread_descr dequeue(pthread_descr * q)
37 pthread_descr th;
38 th = *q;
39 if (th != NULL) {
40 *q = th->p_nextwaiting;
41 th->p_nextwaiting = NULL;
43 return th;
46 static inline int remove_from_queue(pthread_descr * q, pthread_descr th)
48 for (; *q != NULL; q = &((*q)->p_nextwaiting)) {
49 if (*q == th) {
50 *q = th->p_nextwaiting;
51 th->p_nextwaiting = NULL;
52 return 1;
55 return 0;
58 static inline int queue_is_empty(pthread_descr * q)
60 return *q == NULL;