diff options
author | unknown <monty@hundin.mysql.fi> | 2001-12-15 05:12:21 +0200 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2001-12-15 05:12:21 +0200 |
commit | 63e4dec2446382bf0331d2c483daee665064b925 (patch) | |
tree | 5b07ad850f8dba78d186135337dd5a151d18a2b8 /mysys/my_bitmap.c | |
parent | 6a5f89c9b190b0f26fc0cb12595126cba2659f32 (diff) | |
parent | f8b4629cf728072b230159718994f585145b4ce2 (diff) | |
download | mariadb-git-63e4dec2446382bf0331d2c483daee665064b925.tar.gz |
Merge with 3.23.47
extra/resolve_stack_dump.c:
Auto merged
include/my_bitmap.h:
Auto merged
innobase/buf/buf0buf.c:
Auto merged
innobase/dict/dict0crea.c:
Auto merged
mysql-test/t/rpl_get_lock.test:
Auto merged
Diffstat (limited to 'mysys/my_bitmap.c')
-rw-r--r-- | mysys/my_bitmap.c | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index bdaa2c37a2c..7fc094bdb71 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -25,15 +25,33 @@ #include "mysys_priv.h" #include <my_bitmap.h> #include <assert.h> +#include <string.h> -my_bool bitmap_init(MY_BITMAP *map, uint bitmap_size) +inline void bitmap_lock(MY_BITMAP* map) +{ +#ifdef THREAD + if (map->thread_safe) + pthread_mutex_lock(&map->mutex); +#endif +} + +inline void bitmap_unlock(MY_BITMAP* map) +{ +#ifdef THREAD + if (map->thread_safe) + pthread_mutex_unlock(&map->mutex); +#endif +} + +my_bool bitmap_init(MY_BITMAP *map, uint bitmap_size, my_bool thread_safe) { if (!(map->bitmap=(uchar*) my_malloc((bitmap_size+7)/8, MYF(MY_WME | MY_ZEROFILL)))) return 1; DBUG_ASSERT(bitmap_size != ~(uint) 0); #ifdef THREAD - pthread_mutex_init(&map->mutex, MY_MUTEX_INIT_FAST); + if ((map->thread_safe = thread_safe)) + pthread_mutex_init(&map->mutex, MY_MUTEX_INIT_FAST); #endif map->bitmap_size=bitmap_size; return 0; @@ -46,7 +64,8 @@ void bitmap_free(MY_BITMAP *map) my_free((char*) map->bitmap, MYF(0)); map->bitmap=0; #ifdef THREAD - pthread_mutex_destroy(&map->mutex); + if (map->thread_safe) + pthread_mutex_destroy(&map->mutex); #endif } } @@ -55,9 +74,9 @@ void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit) { if (bitmap_bit < map->bitmap_size) { - pthread_mutex_lock(&map->mutex); + bitmap_lock(map); map->bitmap[bitmap_bit / 8] |= (1 << (bitmap_bit & 7)); - pthread_mutex_unlock(&map->mutex); + bitmap_unlock(map); } } @@ -69,7 +88,7 @@ uint bitmap_set_next(MY_BITMAP *map) uint bitmap_size=map->bitmap_size; uint i; - pthread_mutex_lock(&map->mutex); + bitmap_lock(map); for (i=0; i < bitmap_size ; i++, bitmap++) { if (*bitmap != 0xff) @@ -87,7 +106,7 @@ uint bitmap_set_next(MY_BITMAP *map) break; /* Found bit */ } } - pthread_mutex_unlock(&map->mutex); + bitmap_unlock(map); return bit_found; } @@ -96,8 +115,30 @@ void bitmap_clear_bit(MY_BITMAP *map, uint bitmap_bit) { if (bitmap_bit < map->bitmap_size) { - pthread_mutex_lock(&map->mutex); + bitmap_lock(map); map->bitmap[bitmap_bit / 8] &= ~ (1 << (bitmap_bit & 7)); - pthread_mutex_unlock(&map->mutex); + bitmap_unlock(map); } } + + +void bitmap_set_all(MY_BITMAP* map) +{ + bitmap_lock(map); + memset(map->bitmap, 0xff, (map->bitmap_size+7)/8); + bitmap_unlock(map); +} + +my_bool bitmap_is_set(MY_BITMAP* map, uint bitmap_bit) +{ + return (bitmap_bit < map->bitmap_size) ? + (map->bitmap[bitmap_bit / 8] & (1 << (bitmap_bit & 7))) : + 0; +} + +void bitmap_clear_all(MY_BITMAP* map) +{ + bitmap_lock(map); + bzero(map->bitmap,(map->bitmap_size+7)/8); + bitmap_unlock(map); +} |