1 /* $NetBSD: ebh_misc.h,v 1.1 2011/11/24 15:51:32 ahoka 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 /******************************************************************************/
37 /* EBH specific functions */
38 /******************************************************************************/
40 #define CHFS_GET_MEMBER_POS(type, member) \
41 ((unsigned long)(&((type *)0)->member))
43 #define CHFS_GET_LID(lid) (le32toh(lid) & CHFS_LID_DIRTY_BIT_MASK)
46 * EBH_TREE_DESTROY - destroys an RB-tree and frees the memory of its elements.
47 * @name - the RB-tree structure's name
48 * @head - pointer to the RB-tree's head
49 * @type - type of the elements
51 #define EBH_TREE_DESTROY(name, head, type) \
54 for (var = RB_MIN(name, head); var != NULL; var = nxt) { \
55 nxt = RB_NEXT(name, head, var); \
56 RB_REMOVE(name, head, var); \
57 kmem_free(var, sizeof(type)); \
61 /* XXX HACK! we need a clean solution for destroying mutexes in trees */
62 #define EBH_TREE_DESTROY_MUTEX(name, head, type) \
65 for (var = RB_MIN(name, head); var != NULL; var = nxt) { \
66 nxt = RB_NEXT(name, head, var); \
67 RB_REMOVE(name, head, var); \
68 rw_destroy(&var->mutex); \
69 kmem_free(var, sizeof(type)); \
74 * EBH_QUEUE_DESTROY - destroys a TAILQ and frees the memory of its elements.
75 * @head: pointer to the head of the queue
76 * @type: type of the elements
77 * @entry: name of TAILQ_ENTRY
79 #define EBH_QUEUE_DESTROY(head, type, entry) \
82 while ((var = TAILQ_FIRST(head))) { \
83 TAILQ_REMOVE(head, var, entry); \
84 kmem_free(var, sizeof(type)); \
88 #endif /* EBH_MISC_H_ */