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