File: clist.h

package info (click to toggle)
kamailio 4.2.0-2+deb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 56,276 kB
  • sloc: ansic: 552,836; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (127 lines) | stat: -rw-r--r-- 3,307 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * $Id$
 *
 * circular list maintenance macros
 *
 * Copyright (C) 2005 iptelorg GmbH
 *
 * This file is part of ser, a free SIP server.
 *
 * ser is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version
 *
 * ser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*!
 * \file
 * \brief SIP-router core :: circular list maintenance macros
 *
 * \ingroup core
 * Module: \ref core
 */

/* History:
 * --------
 *  2005-08-08  created by andrei
 */

#ifndef _clist_h
#define _clist_h

/*! \brief circular list */
#define clist_init(c, next, prev) \
	do{ \
		(c)->next=(void*)(c); \
		(c)->prev=(void*)(c); \
	} while(0)



/*! \brief adds an entire sublist { s,e } (including s & e )
 * after head
 *
 * \note WARNING: clist_insert_sublist(head, n, n->prev) won't work,
 *          same for clist_insert_sublist(head, n->next, n)
 *  (macro!), use  e=n->prev; clist_insert_sublist(head, n, e, ...)
 *  instead!
 */
#define clist_insert_sublist(head, s, e, next, prev) \
	do{ \
		(s)->prev=(void*)(head); \
		(e)->next=(head)->next; \
		(e)->next->prev=(e); \
		(head)->next=s;   \
	}while(0)



/*! \brief appends an entire sublist { s,e } (including s & e )
 * at the end of the list
 *
 * WARNING: clist_append_sublist(head, n, n->prev, ...) won't work,
 *  (macro!), use  e=n->prev; clist_append_sublist(head, n, e, ...)
 *  instead!
 */
#define clist_append_sublist(head, s, e, next, prev) \
	do{ \
		(s)->prev=(head)->prev; \
		(e)->next=(void*)(head); \
		(s)->prev->next=(s); \
		(head)->prev=(e);   \
	}while(0)




/*! \brief remove sublist { s,e } (including s & e )
 * always, if start is the beginning of the list use
 * clist_rm_sublist(head->next, e, next, prev )
 * WARNING: clist_rm_sublist(n, n->prev, ...) won't work,
 *  (macro!), use  e=n->prev; clist_rm_sublist(n, e, ...)
 *  instead! */
#define clist_rm_sublist(s, e, next, prev) \
	do{\
		(s)->prev->next=(e)->next;  \
		(e)->next->prev=(s)->prev ; \
	}while(0)



/*! \brief insert after (head) */
#define clist_insert(head, c, next, prev) \
	clist_insert_sublist(head, c, c, next, prev)



/*! \brief  append at the end of the list (head->prev) */
#define clist_append(head, c, next, prev) \
	clist_append_sublist(head, c, c, next, prev)



/*! \brief  remove and element */
#define clist_rm(c, next, prev) \
	clist_rm_sublist(c, c, next, prev)



/*! \brief  iterate on a clist */
#define clist_foreach(head, v, dir) \
	for((v)=(head)->dir; (v)!=(void*)(head); (v)=(v)->dir)

/*! \brief  iterate on a clist, safe version (requires an extra bak. var)
 * (it allows removing of the current element) */
#define clist_foreach_safe(head, v, bak,  dir) \
	for((v)=(head)->dir, (bak)=(v)->dir; (v)!=(void*)(head); \
				(v)=(bak), (bak)=(v)->dir)
#endif