--- Gnu-Mach/kern/queue.h 2020/09/02 04:36:57 1.1 +++ Gnu-Mach/kern/queue.h 2020/09/02 04:49:55 1.1.1.5 @@ -1,18 +1,18 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU @@ -79,11 +79,20 @@ typedef struct queue_entry *queue_entry_ #define enqueue(queue,elt) enqueue_tail(queue, elt) #define dequeue(queue) dequeue_head(queue) -void enqueue_head(); -void enqueue_tail(); -queue_entry_t dequeue_head(); -queue_entry_t dequeue_tail(); -void remqueue(); +void enqueue_head(queue_t, queue_entry_t); +void enqueue_tail(queue_t, queue_entry_t); +queue_entry_t dequeue_head(queue_t); +queue_entry_t dequeue_tail(queue_t); +void remqueue(queue_t, queue_entry_t); +void insque(queue_entry_t, queue_entry_t); + +/* + * Macro: queue_assert + * Function: + * Used by macros to assert that the given argument is a + * queue. + */ +#define queue_assert(q) (void) ((void) (q)->next, (q)->prev) /* * Macro: queue_init @@ -103,7 +112,7 @@ void remqueue(); * queue_entry_t queue_first(q) * queue_t q; *IN* */ -#define queue_first(q) ((q)->next) +#define queue_first(q) (queue_assert(q), (q)->next) /* * Macro: queue_next @@ -113,7 +122,7 @@ void remqueue(); * queue_entry_t queue_next(qc) * queue_t qc; */ -#define queue_next(qc) ((qc)->next) +#define queue_next(qc) (queue_assert(qc), (qc)->next) /* * Macro: queue_last @@ -123,7 +132,7 @@ void remqueue(); * queue_entry_t queue_last(q) * queue_t q; *IN* */ -#define queue_last(q) ((q)->prev) +#define queue_last(q) (queue_assert(q), (q)->prev) /* * Macro: queue_prev @@ -133,7 +142,7 @@ void remqueue(); * queue_entry_t queue_prev(qc) * queue_t qc; */ -#define queue_prev(qc) ((qc)->prev) +#define queue_prev(qc) (queue_assert(qc), (qc)->prev) /* * Macro: queue_end @@ -145,7 +154,8 @@ void remqueue(); * queue_t q; * queue_entry_t qe; */ -#define queue_end(q, qe) ((q) == (qe)) +#define queue_end(q, qe) (queue_assert(q), queue_assert(qe), \ + (q) == (qe)) /* * Macro: queue_empty @@ -178,7 +188,9 @@ void remqueue(); */ #define queue_enter(head, elt, type, field) \ { \ - register queue_entry_t prev; \ + queue_assert(head); \ + queue_assert(&(elt)->field); \ + queue_entry_t prev; \ \ prev = (head)->prev; \ if ((head) == prev) { \ @@ -205,7 +217,9 @@ void remqueue(); */ #define queue_enter_first(head, elt, type, field) \ { \ - register queue_entry_t next; \ + queue_assert(head); \ + queue_assert(&(elt)->field); \ + queue_entry_t next; \ \ next = (head)->next; \ if ((head) == next) { \ @@ -238,7 +252,9 @@ void remqueue(); */ #define queue_remove(head, elt, type, field) \ { \ - register queue_entry_t next, prev; \ + queue_assert(head); \ + queue_assert(&(elt)->field); \ + queue_entry_t next, prev; \ \ next = (elt)->field.next; \ prev = (elt)->field.prev; \ @@ -265,7 +281,9 @@ void remqueue(); */ #define queue_remove_first(head, entry, type, field) \ { \ - register queue_entry_t next; \ + queue_assert(head); \ + queue_assert(&(entry)->field); \ + queue_entry_t next; \ \ (entry) = (type) ((head)->next); \ next = (entry)->field.next; \ @@ -288,7 +306,9 @@ void remqueue(); */ #define queue_remove_last(head, entry, type, field) \ { \ - register queue_entry_t prev; \ + queue_assert(head); \ + queue_assert(&(entry)->field); \ + queue_entry_t prev; \ \ (entry) = (type) ((head)->prev); \ prev = (entry)->field.prev; \ @@ -305,6 +325,8 @@ void remqueue(); */ #define queue_assign(to, from, type, field) \ { \ + queue_assert(&(to)->field); \ + queue_assert(&(from)->field); \ ((type)((from)->prev))->field.next = (to); \ ((type)((from)->next))->field.prev = (to); \ *to = *from; \ @@ -366,4 +388,4 @@ typedef struct mpqueue_head mpqueue_head * Old queue stuff, will go away soon. */ -#endif _KERN_QUEUE_H_ +#endif /* _KERN_QUEUE_H_ */