radix-tree.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <linux/preempt.h>
  22. #include <linux/types.h>
  23. struct radix_tree_root {
  24. unsigned int height;
  25. int gfp_mask;
  26. struct radix_tree_node *rnode;
  27. };
  28. #define RADIX_TREE_INIT(mask) { \
  29. .height = 0, \
  30. .gfp_mask = (mask), \
  31. .rnode = NULL, \
  32. }
  33. #define RADIX_TREE(name, mask) \
  34. struct radix_tree_root name = RADIX_TREE_INIT(mask)
  35. #define INIT_RADIX_TREE(root, mask) \
  36. do { \
  37. (root)->height = 0; \
  38. (root)->gfp_mask = (mask); \
  39. (root)->rnode = NULL; \
  40. } while (0)
  41. int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
  42. void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
  43. void *radix_tree_delete(struct radix_tree_root *, unsigned long);
  44. unsigned int
  45. radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
  46. unsigned long first_index, unsigned int max_items);
  47. int radix_tree_preload(int gfp_mask);
  48. void radix_tree_init(void);
  49. void *radix_tree_tag_set(struct radix_tree_root *root,
  50. unsigned long index, int tag);
  51. void *radix_tree_tag_clear(struct radix_tree_root *root,
  52. unsigned long index, int tag);
  53. int radix_tree_tag_get(struct radix_tree_root *root,
  54. unsigned long index, int tag);
  55. unsigned int
  56. radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
  57. unsigned long first_index, unsigned int max_items, int tag);
  58. int radix_tree_tagged(struct radix_tree_root *root, int tag);
  59. static inline void radix_tree_preload_end(void)
  60. {
  61. preempt_enable();
  62. }
  63. #endif /* _LINUX_RADIX_TREE_H */