ebh_misc.h revision 1.1 1 1.1 ahoka /* $NetBSD: ebh_misc.h,v 1.1 2011/11/24 15:51:32 ahoka Exp $ */
2 1.1 ahoka
3 1.1 ahoka /*-
4 1.1 ahoka * Copyright (c) 2010 Department of Software Engineering,
5 1.1 ahoka * University of Szeged, Hungary
6 1.1 ahoka * All rights reserved.
7 1.1 ahoka *
8 1.1 ahoka * This code is derived from software contributed to The NetBSD Foundation
9 1.1 ahoka * by the Department of Software Engineering, University of Szeged, Hungary
10 1.1 ahoka *
11 1.1 ahoka * Redistribution and use in source and binary forms, with or without
12 1.1 ahoka * modification, are permitted provided that the following conditions
13 1.1 ahoka * are met:
14 1.1 ahoka * 1. Redistributions of source code must retain the above copyright
15 1.1 ahoka * notice, this list of conditions and the following disclaimer.
16 1.1 ahoka * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 ahoka * notice, this list of conditions and the following disclaimer in the
18 1.1 ahoka * documentation and/or other materials provided with the distribution.
19 1.1 ahoka *
20 1.1 ahoka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 ahoka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 ahoka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 ahoka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 ahoka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 1.1 ahoka * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 1.1 ahoka * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 1.1 ahoka * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 1.1 ahoka * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 ahoka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 ahoka * SUCH DAMAGE.
31 1.1 ahoka */
32 1.1 ahoka
33 1.1 ahoka #ifndef EBH_MISC_H_
34 1.1 ahoka #define EBH_MISC_H_
35 1.1 ahoka
36 1.1 ahoka /******************************************************************************/
37 1.1 ahoka /* EBH specific functions */
38 1.1 ahoka /******************************************************************************/
39 1.1 ahoka
40 1.1 ahoka #define CHFS_GET_MEMBER_POS(type, member) \
41 1.1 ahoka ((unsigned long)(&((type *)0)->member))
42 1.1 ahoka
43 1.1 ahoka #define CHFS_GET_LID(lid) (le32toh(lid) & CHFS_LID_DIRTY_BIT_MASK)
44 1.1 ahoka
45 1.1 ahoka /**
46 1.1 ahoka * EBH_TREE_DESTROY - destroys an RB-tree and frees the memory of its elements.
47 1.1 ahoka * @name - the RB-tree structure's name
48 1.1 ahoka * @head - pointer to the RB-tree's head
49 1.1 ahoka * @type - type of the elements
50 1.1 ahoka */
51 1.1 ahoka #define EBH_TREE_DESTROY(name, head, type) \
52 1.1 ahoka { \
53 1.1 ahoka type *var, *nxt; \
54 1.1 ahoka for (var = RB_MIN(name, head); var != NULL; var = nxt) { \
55 1.1 ahoka nxt = RB_NEXT(name, head, var); \
56 1.1 ahoka RB_REMOVE(name, head, var); \
57 1.1 ahoka kmem_free(var, sizeof(type)); \
58 1.1 ahoka } \
59 1.1 ahoka }
60 1.1 ahoka
61 1.1 ahoka /* XXX HACK! we need a clean solution for destroying mutexes in trees */
62 1.1 ahoka #define EBH_TREE_DESTROY_MUTEX(name, head, type) \
63 1.1 ahoka { \
64 1.1 ahoka type *var, *nxt; \
65 1.1 ahoka for (var = RB_MIN(name, head); var != NULL; var = nxt) { \
66 1.1 ahoka nxt = RB_NEXT(name, head, var); \
67 1.1 ahoka RB_REMOVE(name, head, var); \
68 1.1 ahoka rw_destroy(&var->mutex); \
69 1.1 ahoka kmem_free(var, sizeof(type)); \
70 1.1 ahoka } \
71 1.1 ahoka }
72 1.1 ahoka
73 1.1 ahoka /**
74 1.1 ahoka * EBH_QUEUE_DESTROY - destroys a TAILQ and frees the memory of its elements.
75 1.1 ahoka * @head: pointer to the head of the queue
76 1.1 ahoka * @type: type of the elements
77 1.1 ahoka * @entry: name of TAILQ_ENTRY
78 1.1 ahoka */
79 1.1 ahoka #define EBH_QUEUE_DESTROY(head, type, entry) \
80 1.1 ahoka { \
81 1.1 ahoka type *var; \
82 1.1 ahoka while ((var = TAILQ_FIRST(head))) { \
83 1.1 ahoka TAILQ_REMOVE(head, var, entry); \
84 1.1 ahoka kmem_free(var, sizeof(type)); \
85 1.1 ahoka } \
86 1.1 ahoka }
87 1.1 ahoka
88 1.1 ahoka #endif /* EBH_MISC_H_ */
89