u_double_list.h revision b9da3791c934e05b82063a8c79c423a0a8e29a94
1/************************************************************************** 2 * 3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 * USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * The above copyright notice and this permission notice (including the 23 * next paragraph) shall be included in all copies or substantial portions 24 * of the Software. 25 * 26 **************************************************************************/ 27 28/** 29 * \file 30 * List macros heavily inspired by the Linux kernel 31 * list handling. No list looping yet. 32 * 33 * Is not threadsafe, so common operations need to 34 * be protected using an external mutex. 35 */ 36 37#ifndef _U_DOUBLE_LIST_H_ 38#define _U_DOUBLE_LIST_H_ 39 40 41#include <stddef.h> 42 43 44struct list_head 45{ 46 struct list_head *prev; 47 struct list_head *next; 48}; 49 50 51#define LIST_INITHEAD(__item) \ 52 do { \ 53 (__item)->prev = (__item); \ 54 (__item)->next = (__item); \ 55 } while (0) 56 57#define LIST_ADD(__item, __list) \ 58 do { \ 59 (__item)->prev = (__list); \ 60 (__item)->next = (__list)->next; \ 61 (__list)->next->prev = (__item); \ 62 (__list)->next = (__item); \ 63 } while (0) 64 65#define LIST_ADDTAIL(__item, __list) \ 66 do { \ 67 (__item)->next = (__list); \ 68 (__item)->prev = (__list)->prev; \ 69 (__list)->prev->next = (__item); \ 70 (__list)->prev = (__item); \ 71 } while(0) 72 73#define LIST_DEL(__item) \ 74 do { \ 75 (__item)->prev->next = (__item)->next; \ 76 (__item)->next->prev = (__item)->prev; \ 77 } while(0) 78 79#define LIST_DELINIT(__item) \ 80 do { \ 81 (__item)->prev->next = (__item)->next; \ 82 (__item)->next->prev = (__item)->prev; \ 83 (__item)->next = (__item); \ 84 (__item)->prev = (__item); \ 85 } while(0) 86 87#define LIST_ENTRY(__type, __item, __field) \ 88 ((__type *)(((char *)(__item)) - offsetof(__type, __field))) 89 90 91#endif /*_U_DOUBLE_LIST_H_*/ 92