86
static inline void bitmap_lock(MY_BITMAP *map)
89
pthread_mutex_lock(map->mutex);
92
static inline void bitmap_unlock(MY_BITMAP *map)
95
pthread_mutex_unlock(map->mutex);
99
bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint32_t n_bits, bool thread_safe)
80
bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint32_t n_bits)
103
84
uint32_t size_in_bytes= bitmap_buffer_size(n_bits);
107
size_in_bytes= ALIGN_SIZE(size_in_bytes);
108
extra= sizeof(pthread_mutex_t);
111
if (!(buf= (my_bitmap_map*) malloc(size_in_bytes+extra)))
85
size_in_bytes= ALIGN_SIZE(size_in_bytes);
86
if (!(buf= (my_bitmap_map*) malloc(size_in_bytes)))
115
map->mutex= (pthread_mutex_t *) ((char*) buf + size_in_bytes);
116
pthread_mutex_init(map->mutex, MY_MUTEX_INIT_FAST);
121
assert(thread_safe == 0);
536
uint32_t bitmap_lock_set_next(MY_BITMAP *map)
540
bit_found= bitmap_set_next(map);
546
void bitmap_lock_clear_bit(MY_BITMAP *map, uint32_t bitmap_bit)
549
assert(map->bitmap && bitmap_bit < map->n_bits);
550
bitmap_clear_bit(map, bitmap_bit);
556
bool bitmap_lock_is_prefix(const MY_BITMAP *map, uint32_t prefix_size)
559
bitmap_lock((MY_BITMAP *)map);
560
res= bitmap_is_prefix(map, prefix_size);
561
bitmap_unlock((MY_BITMAP *)map);
566
void bitmap_lock_set_all(MY_BITMAP *map)
574
void bitmap_lock_clear_all(MY_BITMAP *map)
577
bitmap_clear_all(map);
582
void bitmap_lock_set_prefix(MY_BITMAP *map, uint32_t prefix_size)
585
bitmap_set_prefix(map, prefix_size);
590
bool bitmap_lock_is_clear_all(const MY_BITMAP *map)
593
bitmap_lock((MY_BITMAP *)map);
594
res= bitmap_is_clear_all(map);
595
bitmap_unlock((MY_BITMAP *)map);
600
bool bitmap_lock_is_set_all(const MY_BITMAP *map)
603
bitmap_lock((MY_BITMAP *)map);
604
res= bitmap_is_set_all(map);
605
bitmap_unlock((MY_BITMAP *)map);
610
bool bitmap_lock_is_set(const MY_BITMAP *map, uint32_t bitmap_bit)
613
assert(map->bitmap && bitmap_bit < map->n_bits);
614
bitmap_lock((MY_BITMAP *)map);
615
res= bitmap_is_set(map, bitmap_bit);
616
bitmap_unlock((MY_BITMAP *)map);
621
bool bitmap_lock_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2)
624
bitmap_lock((MY_BITMAP *)map1);
625
bitmap_lock((MY_BITMAP *)map2);
626
res= bitmap_is_subset(map1, map2);
627
bitmap_unlock((MY_BITMAP *)map2);
628
bitmap_unlock((MY_BITMAP *)map1);
633
bool bitmap_lock_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
637
assert(map1->bitmap && map2->bitmap &&
638
map1->n_bits==map2->n_bits);
639
bitmap_lock((MY_BITMAP *)map1);
640
bitmap_lock((MY_BITMAP *)map2);
641
res= bitmap_cmp(map1, map2);
642
bitmap_unlock((MY_BITMAP *)map2);
643
bitmap_unlock((MY_BITMAP *)map1);
648
void bitmap_lock_intersect(MY_BITMAP *map, const MY_BITMAP *map2)
651
bitmap_lock((MY_BITMAP *)map2);
652
bitmap_intersect(map, map2);
653
bitmap_unlock((MY_BITMAP *)map2);
658
void bitmap_lock_subtract(MY_BITMAP *map, const MY_BITMAP *map2)
661
bitmap_lock((MY_BITMAP *)map2);
662
bitmap_subtract(map, map2);
663
bitmap_unlock((MY_BITMAP *)map2);
668
void bitmap_lock_union(MY_BITMAP *map, const MY_BITMAP *map2)
671
bitmap_lock((MY_BITMAP *)map2);
672
bitmap_union(map, map2);
673
bitmap_unlock((MY_BITMAP *)map2);
683
Number of set bits in the bitmap.
685
uint32_t bitmap_lock_bits_set(const MY_BITMAP *map)
688
bitmap_lock((MY_BITMAP *)map);
690
res= bitmap_bits_set(map);
691
bitmap_unlock((MY_BITMAP *)map);
701
Number of first unset bit in the bitmap or MY_BIT_NONE if all bits are set.
703
uint32_t bitmap_lock_get_first(const MY_BITMAP *map)
706
bitmap_lock((MY_BITMAP*)map);
707
res= bitmap_get_first(map);
708
bitmap_unlock((MY_BITMAP*)map);
713
uint32_t bitmap_lock_get_first_set(const MY_BITMAP *map)
716
bitmap_lock((MY_BITMAP*)map);
717
res= bitmap_get_first_set(map);
718
bitmap_unlock((MY_BITMAP*)map);
723
void bitmap_lock_set_bit(MY_BITMAP *map, uint32_t bitmap_bit)
725
assert(map->bitmap && bitmap_bit < map->n_bits);
727
bitmap_set_bit(map, bitmap_bit);
732
void bitmap_lock_flip_bit(MY_BITMAP *map, uint32_t bitmap_bit)
734
assert(map->bitmap && bitmap_bit < map->n_bits);
736
bitmap_flip_bit(map, bitmap_bit);
742
470
uint32_t get_rand_bit(uint32_t bitsize)