lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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. */ |
| 14 | |
| 15 | /* Waiting queues */ |
| 16 | |
| 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. */ |
| 20 | |
| 21 | static __inline__ void enqueue(pthread_descr * q, pthread_descr th) |
| 22 | { |
| 23 | int prio = th->p_priority; |
| 24 | for (; *q != NULL; q = &((*q)->p_nextwaiting)) { |
| 25 | if (prio > (*q)->p_priority) { |
| 26 | th->p_nextwaiting = *q; |
| 27 | *q = th; |
| 28 | return; |
| 29 | } |
| 30 | } |
| 31 | *q = th; |
| 32 | } |
| 33 | |
| 34 | static __inline__ pthread_descr dequeue(pthread_descr * q) |
| 35 | { |
| 36 | pthread_descr th; |
| 37 | th = *q; |
| 38 | if (th != NULL) { |
| 39 | *q = th->p_nextwaiting; |
| 40 | th->p_nextwaiting = NULL; |
| 41 | } |
| 42 | return th; |
| 43 | } |
| 44 | |
| 45 | static __inline__ int remove_from_queue(pthread_descr * q, pthread_descr th) |
| 46 | { |
| 47 | for (; *q != NULL; q = &((*q)->p_nextwaiting)) { |
| 48 | if (*q == th) { |
| 49 | *q = th->p_nextwaiting; |
| 50 | th->p_nextwaiting = NULL; |
| 51 | return 1; |
| 52 | } |
| 53 | } |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static __inline__ int queue_is_empty(pthread_descr * q) |
| 58 | { |
| 59 | return *q == NULL; |
| 60 | } |