Back to index

glibc  2.9
queue.h
Go to the documentation of this file.
00001 /* Linuxthreads - a simple clone()-based implementation of Posix        */
00002 /* threads for Linux.                                                   */
00003 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
00004 /*                                                                      */
00005 /* This program is free software; you can redistribute it and/or        */
00006 /* modify it under the terms of the GNU Library General Public License  */
00007 /* as published by the Free Software Foundation; either version 2       */
00008 /* of the License, or (at your option) any later version.               */
00009 /*                                                                      */
00010 /* This program is distributed in the hope that it will be useful,      */
00011 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
00012 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
00013 /* GNU Library General Public License for more details.                 */
00014 
00015 /* Waiting queues */
00016 
00017 /* Waiting queues are represented by lists of thread descriptors
00018    linked through their p_nextwaiting field.  The lists are kept
00019    sorted by decreasing priority, and then decreasing waiting time. */
00020 
00021 static inline void enqueue(pthread_descr * q, pthread_descr th)
00022 {
00023   int prio = th->p_priority;
00024   ASSERT(th->p_nextwaiting == NULL);
00025   for (; *q != NULL; q = &((*q)->p_nextwaiting)) {
00026     if (prio > (*q)->p_priority) {
00027       th->p_nextwaiting = *q;
00028       *q = th;
00029       return;
00030     }
00031   }
00032   *q = th;
00033 }
00034 
00035 static inline pthread_descr dequeue(pthread_descr * q)
00036 {
00037   pthread_descr th;
00038   th = *q;
00039   if (th != NULL) {
00040     *q = th->p_nextwaiting;
00041     th->p_nextwaiting = NULL;
00042   }
00043   return th;
00044 }
00045 
00046 static inline int remove_from_queue(pthread_descr * q, pthread_descr th)
00047 {
00048   for (; *q != NULL; q = &((*q)->p_nextwaiting)) {
00049     if (*q == th) {
00050       *q = th->p_nextwaiting;
00051       th->p_nextwaiting = NULL;
00052       return 1;
00053     }
00054   }
00055   return 0;
00056 }
00057 
00058 static inline int queue_is_empty(pthread_descr * q)
00059 {
00060     return *q == NULL;
00061 }