1 #include <linux/module.h>
4 #define BIT_ARRAY_BYTES 256
5 #define BIT_RADIX_BITS_PER_ARRAY ((BIT_ARRAY_BYTES - sizeof(unsigned long)) * 8)
7 extern struct kmem_cache
*btrfs_bit_radix_cachep
;
8 int set_radix_bit(struct radix_tree_root
*radix
, unsigned long bit
)
15 slot
= bit
/ BIT_RADIX_BITS_PER_ARRAY
;
16 bit_slot
= bit
% BIT_RADIX_BITS_PER_ARRAY
;
18 bits
= radix_tree_lookup(radix
, slot
);
20 bits
= kmem_cache_alloc(btrfs_bit_radix_cachep
, GFP_NOFS
);
23 memset(bits
+ 1, 0, BIT_ARRAY_BYTES
- sizeof(unsigned long));
25 ret
= radix_tree_insert(radix
, slot
, bits
);
29 ret
= test_and_set_bit(bit_slot
, bits
+ 1);
35 int test_radix_bit(struct radix_tree_root
*radix
, unsigned long bit
)
41 slot
= bit
/ BIT_RADIX_BITS_PER_ARRAY
;
42 bit_slot
= bit
% BIT_RADIX_BITS_PER_ARRAY
;
44 bits
= radix_tree_lookup(radix
, slot
);
47 return test_bit(bit_slot
, bits
+ 1);
50 int clear_radix_bit(struct radix_tree_root
*radix
, unsigned long bit
)
58 slot
= bit
/ BIT_RADIX_BITS_PER_ARRAY
;
59 bit_slot
= bit
% BIT_RADIX_BITS_PER_ARRAY
;
61 bits
= radix_tree_lookup(radix
, slot
);
64 clear_bit(bit_slot
, bits
+ 1);
65 for (i
= 1; i
< BIT_ARRAY_BYTES
/ sizeof(unsigned long); i
++) {
72 bits
= radix_tree_delete(radix
, slot
);
74 kmem_cache_free(btrfs_bit_radix_cachep
, bits
);
79 int find_first_radix_bit(struct radix_tree_root
*radix
, unsigned long *retbits
,
80 unsigned long start
, int nr
)
83 unsigned long *gang
[4];
90 slot
= start
/ BIT_RADIX_BITS_PER_ARRAY
;
91 ret
= radix_tree_gang_lookup(radix
, (void **)gang
, slot
,
93 found
= start
% BIT_RADIX_BITS_PER_ARRAY
;
94 for (i
= 0; i
< ret
&& nr
> 0; i
++) {
97 found
= find_next_bit(bits
+ 1,
98 BIT_RADIX_BITS_PER_ARRAY
,
100 if (found
< BIT_RADIX_BITS_PER_ARRAY
) {
102 BIT_RADIX_BITS_PER_ARRAY
+ found
;
This page took 0.032399 seconds and 5 git commands to generate.