1 /* $NetBSD: ring.h,v 1.1.1.1 2009/06/23 10:09:00 tron Exp $ */ 2 3 #ifndef _RING_H_INCLUDED_ 4 #define _RING_H_INCLUDED_ 5 6 /*++ 7 /* NAME 8 /* ring 3h 9 /* SUMMARY 10 /* circular list management 11 /* SYNOPSIS 12 /* #include <ring.h> 13 /* DESCRIPTION 14 /* .nf 15 16 /* 17 * External interface. 18 */ 19 typedef struct RING RING; 20 21 struct RING { 22 RING *succ; /* successor */ 23 RING *pred; /* predecessor */ 24 }; 25 26 extern void ring_init(RING *); 27 extern void ring_prepend(RING *, RING *); 28 extern void ring_append(RING *, RING *); 29 extern void ring_detach(RING *); 30 31 #define ring_succ(c) ((c)->succ) 32 #define ring_pred(c) ((c)->pred) 33 34 #define RING_FOREACH(entry, head) \ 35 for (entry = ring_succ(head); entry != (head); entry = ring_succ(entry)) 36 37 /* 38 * Typically, an application will embed a RING structure into a larger 39 * structure that also contains application-specific members. This approach 40 * gives us the best of both worlds. The application can still use the 41 * generic RING primitives for manipulating RING structures. The macro below 42 * transforms a pointer from RING structure to the structure that contains 43 * it. 44 */ 45 #define RING_TO_APPL(ring_ptr,app_type,ring_member) \ 46 ((app_type *) (((char *) (ring_ptr)) - offsetof(app_type,ring_member))) 47 48 /* LICENSE 49 /* .ad 50 /* .fi 51 /* The Secure Mailer license must be distributed with this software. 52 /* AUTHOR(S) 53 /* Wietse Venema 54 /* IBM T.J. Watson Research 55 /* P.O. Box 704 56 /* Yorktown Heights, NY 10598, USA 57 /* LAST MODIFICATION 58 /* Tue Jan 28 16:50:20 EST 1997 59 /*--*/ 60 61 #endif 62