blob: cbfa1153742120d4a01798e181a06815555281e6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/preempt.h>
23#include <linux/types.h>
24
Nick Piggin612d6c12006-06-23 02:03:22 -070025#define RADIX_TREE_MAX_TAGS 2
26
27/* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028struct radix_tree_root {
29 unsigned int height;
Al Virofd4f2df2005-10-21 03:18:50 -040030 gfp_t gfp_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 struct radix_tree_node *rnode;
32};
33
34#define RADIX_TREE_INIT(mask) { \
35 .height = 0, \
36 .gfp_mask = (mask), \
37 .rnode = NULL, \
38}
39
40#define RADIX_TREE(name, mask) \
41 struct radix_tree_root name = RADIX_TREE_INIT(mask)
42
43#define INIT_RADIX_TREE(root, mask) \
44do { \
45 (root)->height = 0; \
46 (root)->gfp_mask = (mask); \
47 (root)->rnode = NULL; \
48} while (0)
49
50int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
51void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
Hans Reisera4331362005-11-07 00:59:29 -080052void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053void *radix_tree_delete(struct radix_tree_root *, unsigned long);
54unsigned int
55radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
56 unsigned long first_index, unsigned int max_items);
Al Virodd0fc662005-10-07 07:46:04 +010057int radix_tree_preload(gfp_t gfp_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058void radix_tree_init(void);
59void *radix_tree_tag_set(struct radix_tree_root *root,
Jonathan Corbetdaff89f2006-03-25 03:08:05 -080060 unsigned long index, unsigned int tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061void *radix_tree_tag_clear(struct radix_tree_root *root,
Jonathan Corbetdaff89f2006-03-25 03:08:05 -080062 unsigned long index, unsigned int tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063int radix_tree_tag_get(struct radix_tree_root *root,
Jonathan Corbetdaff89f2006-03-25 03:08:05 -080064 unsigned long index, unsigned int tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065unsigned int
66radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
Jonathan Corbetdaff89f2006-03-25 03:08:05 -080067 unsigned long first_index, unsigned int max_items,
68 unsigned int tag);
69int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71static inline void radix_tree_preload_end(void)
72{
73 preempt_enable();
74}
75
76#endif /* _LINUX_RADIX_TREE_H */