Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6] / include / linux / radix-tree.h
1 /*
2  * Copyright (C) 2001 Momchil Velikov
3  * Portions Copyright (C) 2001 Christoph Hellwig
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 #ifndef _LINUX_RADIX_TREE_H
20 #define _LINUX_RADIX_TREE_H
21
22 #include <linux/sched.h>
23 #include <linux/preempt.h>
24 #include <linux/types.h>
25
26 #define RADIX_TREE_MAX_TAGS 2
27
28 /* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */
29 struct radix_tree_root {
30         unsigned int            height;
31         gfp_t                   gfp_mask;
32         struct radix_tree_node  *rnode;
33 };
34
35 #define RADIX_TREE_INIT(mask)   {                                       \
36         .height = 0,                                                    \
37         .gfp_mask = (mask),                                             \
38         .rnode = NULL,                                                  \
39 }
40
41 #define RADIX_TREE(name, mask) \
42         struct radix_tree_root name = RADIX_TREE_INIT(mask)
43
44 #define INIT_RADIX_TREE(root, mask)                                     \
45 do {                                                                    \
46         (root)->height = 0;                                             \
47         (root)->gfp_mask = (mask);                                      \
48         (root)->rnode = NULL;                                           \
49 } while (0)
50
51 int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
52 void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
53 void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
54 void *radix_tree_delete(struct radix_tree_root *, unsigned long);
55 unsigned int
56 radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
57                         unsigned long first_index, unsigned int max_items);
58 int radix_tree_preload(gfp_t gfp_mask);
59 void radix_tree_init(void);
60 void *radix_tree_tag_set(struct radix_tree_root *root,
61                         unsigned long index, unsigned int tag);
62 void *radix_tree_tag_clear(struct radix_tree_root *root,
63                         unsigned long index, unsigned int tag);
64 int radix_tree_tag_get(struct radix_tree_root *root,
65                         unsigned long index, unsigned int tag);
66 unsigned int
67 radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
68                 unsigned long first_index, unsigned int max_items,
69                 unsigned int tag);
70 int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
71
72 static inline void radix_tree_preload_end(void)
73 {
74         preempt_enable();
75 }
76
77 #endif /* _LINUX_RADIX_TREE_H */