| 136 | |
| 137 | |
| 138 | my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits, |
| 139 | my_bool thread_safe __attribute__((unused))) |
| 140 | { |
| 141 | DBUG_ENTER("bitmap_init"); |
| 142 | if (!buf) |
| 143 | { |
| 144 | uint size_in_bytes= bitmap_buffer_size(n_bits); |
| 145 | uint extra= 0; |
| 146 | |
| 147 | if (thread_safe) |
| 148 | { |
| 149 | size_in_bytes= ALIGN_SIZE(size_in_bytes); |
| 150 | extra= sizeof(mysql_mutex_t); |
| 151 | } |
| 152 | map->mutex= 0; |
| 153 | |
| 154 | if (!(buf= (my_bitmap_map*) my_malloc(size_in_bytes+extra, MYF(MY_WME)))) |
| 155 | DBUG_RETURN(1); |
| 156 | |
| 157 | if (thread_safe) |
| 158 | { |
| 159 | map->mutex= (mysql_mutex_t *) ((char*) buf + size_in_bytes); |
| 160 | mysql_mutex_init(key_BITMAP_mutex, map->mutex, MY_MUTEX_INIT_FAST); |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | |
| 165 | else |
| 166 | { |
| 167 | DBUG_ASSERT(thread_safe == 0); |
| 168 | map->mutex= NULL; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | map->bitmap= buf; |
| 173 | map->n_bits= n_bits; |
| 174 | create_last_word_mask(map); |
| 175 | bitmap_clear_all(map); |
| 176 | DBUG_RETURN(0); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | void bitmap_free(MY_BITMAP *map) |
no test coverage detected