diff options
author | monty@donna.mysql.com <> | 2001-02-07 17:42:20 +0200 |
---|---|---|
committer | monty@donna.mysql.com <> | 2001-02-07 17:42:20 +0200 |
commit | d487e5a9b1702ffaeb7afd8656cd811be1493576 (patch) | |
tree | 513c37217d346353220e5bf7b3bcccd9e135c596 /mysys/my_bitmap.c | |
parent | cc9f24bc40220c38d40b064e4b07c4192ee9a8b8 (diff) | |
download | mariadb-git-d487e5a9b1702ffaeb7afd8656cd811be1493576.tar.gz |
Use new bitmap interface
Patches for Armstrong
Removed warnings when using REPAIR TABLE .. EXTENDED
Diffstat (limited to 'mysys/my_bitmap.c')
-rw-r--r-- | mysys/my_bitmap.c | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index 848df42d4d4..2601aa96727 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -20,33 +20,58 @@ We assume that the size of the used bitmap is less than ~(uint) 0 TODO: - - create an unique structure for this that includes the mutex and bitmap size - make a init function that will allocate the bitmap and init the mutex - make an end function that will free everything + Make assembler THREAD safe versions of these using test-and-set instructions */ #include "mysys_priv.h" #include <my_bitmap.h> +#include <assert.h> pthread_mutex_t LOCK_bitmap; -void bitmap_set_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit) +my_bool bitmap_init(BITMAP *map, uint bitmap_size) +{ + if (!(map->bitmap=(uchar*) my_malloc((bitmap_size+7)/8,MYF(MY_WME)))) + return 1; + dbug_assert(bitmap_size != ~(uint) 0); +#ifdef THREAD + pthread_mutex_init(&map->mutex, NULL); +#endif + map->bitmap_size=bitmap_size; + return 0; +} + +void bitmap_free(BITMAP *map) +{ + if (map->bitmap) + { + my_free((char*) map->bitmap, MYF(0)); + map->bitmap=0; +#ifdef THREAD + pthread_mutex_destroy(&map->mutex); +#endif + } +} + +void bitmap_set_bit(BITMAP *map, uint bitmap_bit) { - if (bitmap_bit < bitmap_size*8) + if (bitmap_bit < map->bitmap_size) { - pthread_mutex_lock(&LOCK_bitmap); - bitmap[bitmap_bit / 8] |= (1 << (bitmap_bit & 7)); - pthread_mutex_unlock(&LOCK_bitmap); + pthread_mutex_lock(&map->mutex); + map->bitmap[bitmap_bit / 8] |= (1 << (bitmap_bit & 7)); + pthread_mutex_unlock(&map->mutex); } } -uint bitmap_set_next(uchar *bitmap, uint bitmap_size) + +uint bitmap_set_next(BITMAP *map) { + uchar *bitmap=map->bitmap; uint bit_found = MY_BIT_NONE; + uint bitmap_size=map->bitmap_size; uint i; - pthread_mutex_lock(&LOCK_bitmap); + pthread_mutex_lock(&map->mutex); for (i=0; i < bitmap_size ; i++, bitmap++) { if (*bitmap != 0xff) @@ -64,18 +89,18 @@ uint bitmap_set_next(uchar *bitmap, uint bitmap_size) break; /* Found bit */ } } - pthread_mutex_unlock(&LOCK_bitmap); + pthread_mutex_unlock(&map->mutex); return bit_found; } -void bitmap_clear_bit(uchar *bitmap, uint bitmap_size, uint bitmap_bit) +void bitmap_clear_bit(BITMAP *map, uint bitmap_bit) { - if (bitmap_bit < bitmap_size*8) + if (bitmap_bit < map->bitmap_size) { - pthread_mutex_lock(&LOCK_bitmap); - bitmap[bitmap_bit / 8] &= ~ (1 << (bitmap_bit & 7)); - pthread_mutex_unlock(&LOCK_bitmap); + pthread_mutex_lock(&map->mutex); + map->bitmap[bitmap_bit / 8] &= ~ (1 << (bitmap_bit & 7)); + pthread_mutex_unlock(&map->mutex); } } |