summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/array.c21
-rw-r--r--mysys/hash.c22
-rw-r--r--mysys/my_alloc.c268
-rw-r--r--mysys/my_bitmap.c69
-rw-r--r--mysys/my_default.c6
-rw-r--r--mysys/my_delete.c2
-rw-r--r--mysys/my_init.c11
-rw-r--r--mysys/my_lockmem.c4
-rw-r--r--mysys/my_malloc.c2
-rw-r--r--mysys/my_uuid.c31
-rw-r--r--mysys/thr_mutex.c9
-rw-r--r--mysys/waiting_threads.c2
12 files changed, 248 insertions, 199 deletions
diff --git a/mysys/array.c b/mysys/array.c
index 32606cafb23..c9bf609b6d4 100644
--- a/mysys/array.c
+++ b/mysys/array.c
@@ -41,8 +41,9 @@
*/
my_bool init_dynamic_array2(PSI_memory_key psi_key, DYNAMIC_ARRAY *array,
- uint element_size, void *init_buffer,
- uint init_alloc, uint alloc_increment, myf my_flags)
+ size_t element_size, void *init_buffer,
+ size_t init_alloc, size_t alloc_increment,
+ myf my_flags)
{
DBUG_ENTER("init_dynamic_array2");
if (!alloc_increment)
@@ -198,7 +199,7 @@ void *pop_dynamic(DYNAMIC_ARRAY *array)
FALSE Ok
*/
-my_bool set_dynamic(DYNAMIC_ARRAY *array, const void *element, uint idx)
+my_bool set_dynamic(DYNAMIC_ARRAY *array, const void *element, size_t idx)
{
if (idx >= array->elements)
{
@@ -209,7 +210,7 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, const void *element, uint idx)
array->elements=idx+1;
}
memcpy(array->buffer+(idx * array->size_of_element),element,
- (size_t) array->size_of_element);
+ array->size_of_element);
return FALSE;
}
@@ -230,13 +231,13 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, const void *element, uint idx)
TRUE Allocation of new memory failed
*/
-my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements)
+my_bool allocate_dynamic(DYNAMIC_ARRAY *array, size_t max_elements)
{
DBUG_ENTER("allocate_dynamic");
if (max_elements >= array->max_element)
{
- uint size;
+ size_t size;
uchar *new_ptr;
size= (max_elements + array->alloc_increment)/array->alloc_increment;
size*= array->alloc_increment;
@@ -277,7 +278,7 @@ my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements)
idx Index of element wanted.
*/
-void get_dynamic(DYNAMIC_ARRAY *array, void *element, uint idx)
+void get_dynamic(DYNAMIC_ARRAY *array, void *element, size_t idx)
{
if (idx >= array->elements)
{
@@ -320,7 +321,7 @@ void delete_dynamic(DYNAMIC_ARRAY *array)
idx Index of element to be deleted
*/
-void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx)
+void delete_dynamic_element(DYNAMIC_ARRAY *array, size_t idx)
{
char *ptr= (char*) array->buffer+array->size_of_element*idx;
array->elements--;
@@ -339,7 +340,7 @@ void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx)
deleting the array;
*/
void delete_dynamic_with_callback(DYNAMIC_ARRAY *array, FREE_FUNC f) {
- uint i;
+ size_t i;
char *ptr= (char*) array->buffer;
for (i= 0; i < array->elements; i++, ptr+= array->size_of_element) {
f(ptr);
@@ -357,7 +358,7 @@ void delete_dynamic_with_callback(DYNAMIC_ARRAY *array, FREE_FUNC f) {
void freeze_size(DYNAMIC_ARRAY *array)
{
- uint elements;
+ size_t elements;
/*
Do nothing if we are using a static buffer
diff --git a/mysys/hash.c b/mysys/hash.c
index abc11b42500..d9132b28cd7 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -76,8 +76,8 @@ my_hash_value_type my_hash_sort(CHARSET_INFO *cs, const uchar *key,
@retval 1 failure
*/
my_bool
-my_hash_init2(PSI_memory_key psi_key, HASH *hash, uint growth_size,
- CHARSET_INFO *charset, ulong size, size_t key_offset,
+my_hash_init2(PSI_memory_key psi_key, HASH *hash, size_t growth_size,
+ CHARSET_INFO *charset, size_t size, size_t key_offset,
size_t key_length, my_hash_get_key get_key,
my_hash_function hash_function,
void (*free_element)(void*), uint flags)
@@ -282,6 +282,8 @@ uchar* my_hash_first_from_hash_value(const HASH *hash,
uint flag= 1;
uint idx= my_hash_mask(hash_value,
hash->blength, hash->records);
+ if (!length)
+ length= hash->key_length; // length for fixed length keys or 0
do
{
pos= dynamic_element(&hash->array,idx,HASH_LINK*);
@@ -316,6 +318,8 @@ uchar* my_hash_next(const HASH *hash, const uchar *key, size_t length,
if (*current_record != NO_RECORD)
{
HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*);
+ if (!length)
+ length= hash->key_length; // length for fixed length keys or 0
for (idx=data[*current_record].next; idx != NO_RECORD ; idx=pos->next)
{
pos=data+idx;
@@ -356,8 +360,11 @@ static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink)
length length of key
NOTES:
- If length is 0, comparison is done using the length of the
- record being compared against.
+ length equal 0 can mean 2 things:
+ 1) it is fixed key length hash (HASH::key_length != 0) and
+ default length should be taken in this case
+ 2) it is really 0 length key for variable key length hash
+ (HASH::key_length == 0)
RETURN
= 0 key of record == key
@@ -368,10 +375,11 @@ static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key,
size_t length)
{
size_t rec_keylength;
- uchar *rec_key= (uchar*) my_hash_key(hash, pos->data, &rec_keylength, 1);
- return ((length && length != rec_keylength) ||
+ uchar *rec_key;
+ rec_key= (uchar*) my_hash_key(hash, pos->data, &rec_keylength, 1);
+ return (length != rec_keylength) ||
my_strnncoll(hash->charset, (uchar*) rec_key, rec_keylength,
- (uchar*) key, rec_keylength));
+ (uchar*) key, rec_keylength);
}
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 3e0b774b0c7..9f230b6bbcb 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -20,15 +20,101 @@
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
+#include <my_bit.h>
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
#undef EXTRA_DEBUG
#define EXTRA_DEBUG
/* data packed in MEM_ROOT -> min_malloc */
-#define MALLOC_FLAG(A) ((A & 1) ? MY_THREAD_SPECIFIC : 0)
+/* Don't allocate too small blocks */
+#define ROOT_MIN_BLOCK_SIZE 256
+
+/* bits in MEM_ROOT->flags */
+#define ROOT_FLAG_THREAD_SPECIFIC 1
+#define ROOT_FLAG_MPROTECT 2
+
+#define MALLOC_FLAG(R) MYF((R)->flags & ROOT_FLAG_THREAD_SPECIFIC ? THREAD_SPECIFIC : 0)
#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
+
+/*
+ Alloc memory through either my_malloc or mmap()
+*/
+
+static void *root_alloc(MEM_ROOT *root, size_t size, size_t *alloced_size,
+ myf my_flags)
+{
+ *alloced_size= size;
+#if defined(HAVE_MMAP) && defined(HAVE_MPROTECT) && defined(MAP_ANONYMOUS)
+ if (root->flags & ROOT_FLAG_MPROTECT)
+ {
+ void *res;
+ *alloced_size= MY_ALIGN(size, my_system_page_size);
+ res= my_mmap(0, *alloced_size, PROT_READ | PROT_WRITE,
+ MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (res == MAP_FAILED)
+ res= 0;
+ return res;
+ }
+#endif /* HAVE_MMAP */
+
+ return my_malloc(root->psi_key, size,
+ my_flags | MYF(root->flags & ROOT_FLAG_THREAD_SPECIFIC ?
+ MY_THREAD_SPECIFIC : 0));
+}
+
+static void root_free(MEM_ROOT *root, void *ptr, size_t size)
+{
+#if defined(HAVE_MMAP) && defined(HAVE_MPROTECT) && defined(MAP_ANONYMOUS)
+ if (root->flags & ROOT_FLAG_MPROTECT)
+ my_munmap(ptr, size);
+ else
+#endif
+ my_free(ptr);
+}
+
+
+/*
+ Calculate block sizes to use
+
+ Sizes will be updated to next power of 2, minus operating system
+ memory management size.
+
+ The idea is to reduce memory fragmentation as most system memory
+ allocators are using power of 2 block size internally.
+*/
+
+static void calculate_block_sizes(MEM_ROOT *mem_root, size_t block_size,
+ size_t *pre_alloc_size)
+{
+ size_t pre_alloc= *pre_alloc_size;
+
+ if (mem_root->flags&= ROOT_FLAG_MPROTECT)
+ {
+ mem_root->block_size= MY_ALIGN(block_size, my_system_page_size);
+ if (pre_alloc)
+ pre_alloc= MY_ALIGN(pre_alloc, my_system_page_size);
+ }
+ else
+ {
+ DBUG_ASSERT(block_size <= UINT_MAX32);
+ mem_root->block_size= (my_round_up_to_next_power((uint32) block_size -
+ MALLOC_OVERHEAD)-
+ MALLOC_OVERHEAD);
+ if (pre_alloc)
+ pre_alloc= (my_round_up_to_next_power((uint32) pre_alloc -
+ MALLOC_OVERHEAD)-
+ MALLOC_OVERHEAD);
+ }
+ *pre_alloc_size= pre_alloc;
+}
+
+
/*
Initialize memory root
@@ -36,13 +122,18 @@
init_alloc_root()
mem_root - memory root to initialize
name - name of memroot (for debugging)
- block_size - size of chunks (blocks) used for memory allocation
+ block_size - size of chunks (blocks) used for memory allocation.
+ Will be updated to next power of 2, minus
+ internal and system memory management size. This is
+ will reduce memory fragmentation as most system memory
+ allocators are using power of 2 block size internally.
(It is external size of chunk i.e. it should include
memory required for internal structures, thus it
- should be no less than ALLOC_ROOT_MIN_BLOCK_SIZE)
+ should be no less than ROOT_MIN_BLOCK_SIZE).
pre_alloc_size - if non-0, then size of block that should be
pre-allocated during memory root initialization.
my_flags MY_THREAD_SPECIFIC flag for my_malloc
+ MY_RROOT_USE_MPROTECT for read only protected memory
DESCRIPTION
This function prepares memory root for further use, sets initial size of
@@ -50,9 +141,6 @@
Although error can happen during execution of this function if
pre_alloc_size is non-0 it won't be reported. Instead it will be
reported as error in first alloc_root() on this memory root.
-
- We don't want to change the structure size for MEM_ROOT.
- Because of this, we store in MY_THREAD_SPECIFIC as bit 1 in block_size
*/
void init_alloc_root(PSI_memory_key key, MEM_ROOT *mem_root, size_t block_size,
@@ -63,25 +151,31 @@ void init_alloc_root(PSI_memory_key key, MEM_ROOT *mem_root, size_t block_size,
DBUG_PRINT("enter",("root: %p prealloc: %zu", mem_root, pre_alloc_size));
mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
- mem_root->min_malloc= 32;
- mem_root->block_size= (block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1;
+ mem_root->min_malloc= 32 + REDZONE_SIZE;
+ mem_root->block_size= MY_MAX(block_size, ROOT_MIN_BLOCK_SIZE);
+ mem_root->flags= 0;
if (my_flags & MY_THREAD_SPECIFIC)
- mem_root->block_size|= 1;
+ mem_root->flags|= ROOT_FLAG_THREAD_SPECIFIC;
+ if (my_flags & MY_ROOT_USE_MPROTECT)
+ mem_root->flags|= ROOT_FLAG_MPROTECT;
+
+ calculate_block_sizes(mem_root, block_size, &pre_alloc_size);
mem_root->error_handler= 0;
mem_root->block_num= 4; /* We shift this with >>2 */
mem_root->first_block_usage= 0;
- mem_root->m_psi_key= key;
+ mem_root->psi_key= key;
#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
{
- size_t size= pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM));
+ size_t alloced_size;
if ((mem_root->free= mem_root->pre_alloc=
- (USED_MEM*) my_malloc(key, size, MYF(my_flags))))
+ (USED_MEM*) root_alloc(mem_root, pre_alloc_size, &alloced_size,
+ MYF(0))))
{
- mem_root->free->size= size;
- mem_root->free->left= pre_alloc_size;
+ mem_root->free->size= alloced_size;
+ mem_root->free->left= alloced_size - ALIGN_SIZE(sizeof(USED_MEM));
mem_root->free->next= 0;
TRASH_MEM(mem_root->free);
}
@@ -113,13 +207,14 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
DBUG_ENTER("reset_root_defaults");
DBUG_ASSERT(alloc_root_inited(mem_root));
- mem_root->block_size= (((block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1) |
- (mem_root->block_size & 1));
+ calculate_block_sizes(mem_root, block_size, &pre_alloc_size);
+
#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
{
- size_t size= pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM));
- if (!mem_root->pre_alloc || mem_root->pre_alloc->size != size)
+ size_t size= mem_root->block_size, alloced_size;
+ if (!mem_root->pre_alloc ||
+ mem_root->pre_alloc->size != mem_root->block_size)
{
USED_MEM *mem, **prev= &mem_root->free;
/*
@@ -139,26 +234,23 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
{
/* remove block from the list and free it */
*prev= mem->next;
- my_free(mem);
+ root_free(mem_root, mem, mem->size);
}
else
prev= &mem->next;
}
/* Allocate new prealloc block and add it to the end of free list */
- if ((mem= (USED_MEM *) my_malloc(mem_root->m_psi_key, size,
- MYF(MALLOC_FLAG(mem_root->
- block_size)))))
+ if ((mem= (USED_MEM *) root_alloc(mem_root, size, &alloced_size,
+ MYF(MY_WME))))
{
- mem->size= size;
- mem->left= pre_alloc_size;
+ mem->size= alloced_size;
+ mem->left= alloced_size - ALIGN_SIZE(sizeof(USED_MEM));
mem->next= *prev;
*prev= mem_root->pre_alloc= mem;
TRASH_MEM(mem);
}
else
- {
mem_root->pre_alloc= 0;
- }
}
}
else
@@ -171,37 +263,6 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
void *alloc_root(MEM_ROOT *mem_root, size_t length)
{
-#if defined(HAVE_valgrind) && defined(EXTRA_DEBUG)
- reg1 USED_MEM *next;
- DBUG_ENTER("alloc_root");
- DBUG_PRINT("enter",("root: %p", mem_root));
-
- DBUG_ASSERT(alloc_root_inited(mem_root));
-
- DBUG_EXECUTE_IF("simulate_out_of_memory",
- {
- if (mem_root->error_handler)
- (*mem_root->error_handler)();
- DBUG_SET("-d,simulate_out_of_memory");
- DBUG_RETURN((void*) 0); /* purecov: inspected */
- });
-
- length+=ALIGN_SIZE(sizeof(USED_MEM));
- if (!(next = (USED_MEM*) my_malloc(mem_root->m_psi_key, length,
- MYF(MY_WME | ME_FATAL |
- MALLOC_FLAG(mem_root->block_size)))))
- {
- if (mem_root->error_handler)
- (*mem_root->error_handler)();
- DBUG_RETURN((uchar*) 0); /* purecov: inspected */
- }
- next->next= mem_root->used;
- next->left= 0;
- next->size= length;
- mem_root->used= next;
- DBUG_PRINT("exit",("ptr: %p", (((char*)next)+ALIGN_SIZE(sizeof(USED_MEM)))));
- DBUG_RETURN((((uchar*) next)+ALIGN_SIZE(sizeof(USED_MEM))));
-#else
size_t get_size, block_size;
uchar* point;
reg1 USED_MEM *next= 0;
@@ -212,13 +273,36 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_ASSERT(alloc_root_inited(mem_root));
DBUG_EXECUTE_IF("simulate_out_of_memory",
- {
- /* Avoid reusing an already allocated block */
- if (mem_root->error_handler)
- (*mem_root->error_handler)();
- DBUG_SET("-d,simulate_out_of_memory");
- DBUG_RETURN((void*) 0); /* purecov: inspected */
- });
+ {
+ if (mem_root->error_handler)
+ (*mem_root->error_handler)();
+ DBUG_SET("-d,simulate_out_of_memory");
+ DBUG_RETURN((void*) 0); /* purecov: inspected */
+ });
+
+#if defined(HAVE_valgrind) && defined(EXTRA_DEBUG)
+ if (!(mem_root->flags & ROOT_FLAG_MPROTECT))
+ {
+ length+= ALIGN_SIZE(sizeof(USED_MEM));
+ if (!(next = (USED_MEM*) my_malloc(mem_root->psi_key, length,
+ MYF(MY_WME | ME_FATAL |
+ (mem_root->flags &
+ ROOT_FLAG_THREAD_SPECIFIC ?
+ MY_THREAD_SPECIFIC : 0)))))
+ {
+ if (mem_root->error_handler)
+ (*mem_root->error_handler)();
+ DBUG_RETURN((uchar*) 0); /* purecov: inspected */
+ }
+ next->next= mem_root->used;
+ next->left= 0;
+ next->size= length;
+ mem_root->used= next;
+ DBUG_PRINT("exit",("ptr: %p", (((char*)next)+ALIGN_SIZE(sizeof(USED_MEM)))));
+ DBUG_RETURN((((uchar*) next)+ALIGN_SIZE(sizeof(USED_MEM))));
+ }
+#endif /* defined(HAVE_valgrind) && defined(EXTRA_DEBUG) */
+
length= ALIGN_SIZE(length) + REDZONE_SIZE;
if ((*(prev= &mem_root->free)) != NULL)
{
@@ -237,14 +321,16 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
}
if (! next)
{ /* Time to alloc new block */
- block_size= (mem_root->block_size & ~1) * (mem_root->block_num >> 2);
- get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
+ size_t alloced_length;
+
+ /* Increase block size over time if there is a lot of mallocs */
+ block_size= (MY_ALIGN(mem_root->block_size, ROOT_MIN_BLOCK_SIZE) *
+ (mem_root->block_num >> 2)- MALLOC_OVERHEAD);
+ get_size= length + ALIGN_SIZE(sizeof(USED_MEM));
get_size= MY_MAX(get_size, block_size);
- if (!(next = (USED_MEM*) my_malloc(mem_root->m_psi_key, get_size,
- MYF(MY_WME | ME_FATAL |
- MALLOC_FLAG(mem_root->
- block_size)))))
+ if (!(next= (USED_MEM*) root_alloc(mem_root, get_size, &alloced_length,
+ MYF(MY_WME | ME_FATAL))))
{
if (mem_root->error_handler)
(*mem_root->error_handler)();
@@ -252,8 +338,8 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
}
mem_root->block_num++;
next->next= *prev;
- next->size= get_size;
- next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
+ next->size= alloced_length;
+ next->left= alloced_length - ALIGN_SIZE(sizeof(USED_MEM));
*prev=next;
TRASH_MEM(next);
}
@@ -271,7 +357,6 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
TRASH_ALLOC(point, original_length);
DBUG_PRINT("exit",("ptr: %p", point));
DBUG_RETURN((void*) point);
-#endif
}
@@ -407,13 +492,13 @@ void free_root(MEM_ROOT *root, myf MyFlags)
{
old=next; next= next->next ;
if (old != root->pre_alloc)
- my_free(old);
+ root_free(root, old, old->size);
}
for (next=root->free ; next ;)
{
old=next; next= next->next;
if (old != root->pre_alloc)
- my_free(old);
+ root_free(root, old, old->size);
}
root->used=root->free=0;
if (root->pre_alloc)
@@ -428,6 +513,7 @@ void free_root(MEM_ROOT *root, myf MyFlags)
DBUG_VOID_RETURN;
}
+
/*
Find block that contains an object and set the pre_alloc to it
*/
@@ -454,6 +540,38 @@ void set_prealloc_root(MEM_ROOT *root, char *ptr)
}
+/**
+ Change protection for all blocks in the mem root
+*/
+
+#if defined(HAVE_MMAP) && defined(HAVE_MPROTECT) && defined(MAP_ANONYMOUS)
+void protect_root(MEM_ROOT *root, int prot)
+{
+ reg1 USED_MEM *next,*old;
+ DBUG_ENTER("protect_root");
+ DBUG_PRINT("enter",("root: %p prot: %d", root, prot));
+
+ DBUG_ASSERT(root->flags & ROOT_FLAG_MPROTECT);
+
+ for (next= root->used; next ;)
+ {
+ old= next; next= next->next ;
+ mprotect(old, old->size, prot);
+ }
+ for (next= root->free; next ;)
+ {
+ old= next; next= next->next ;
+ mprotect(old, old->size, prot);
+ }
+ DBUG_VOID_RETURN;
+}
+#else
+void protect_root(MEM_ROOT *root, int prot)
+{
+}
+#endif /* defined(HAVE_MMAP) && ... */
+
+
char *strdup_root(MEM_ROOT *root, const char *str)
{
return strmake_root(root, str, strlen(str));
diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c
index bf2bacd213c..9893c7e4a58 100644
--- a/mysys/my_bitmap.c
+++ b/mysys/my_bitmap.c
@@ -123,19 +123,6 @@ static inline my_bitmap_map last_word_mask(uint bit)
}
-static inline void bitmap_lock(MY_BITMAP *map __attribute__((unused)))
-{
- if (map->mutex)
- mysql_mutex_lock(map->mutex);
-}
-
-static inline void bitmap_unlock(MY_BITMAP *map __attribute__((unused)))
-{
- if (map->mutex)
- mysql_mutex_unlock(map->mutex);
-}
-
-
static inline uint get_first_set(my_bitmap_map value, uint word_pos)
{
uchar *byte_ptr= (uchar*)&value;
@@ -159,32 +146,15 @@ static inline uint get_first_set(my_bitmap_map value, uint word_pos)
Initialize a bitmap object. All bits will be set to zero
*/
-my_bool my_bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits,
- my_bool thread_safe)
+my_bool my_bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits)
{
DBUG_ENTER("my_bitmap_init");
- map->mutex= 0;
if (!buf)
{
uint size_in_bytes= bitmap_buffer_size(n_bits);
- uint extra= 0;
- if (thread_safe)
- {
- size_in_bytes= ALIGN_SIZE(size_in_bytes);
- extra= sizeof(mysql_mutex_t);
- }
if (!(buf= (my_bitmap_map*) my_malloc(key_memory_MY_BITMAP_bitmap,
- size_in_bytes+extra, MYF(MY_WME))))
+ size_in_bytes, MYF(MY_WME))))
DBUG_RETURN(1);
- if (thread_safe)
- {
- map->mutex= (mysql_mutex_t *) ((char*) buf + size_in_bytes);
- mysql_mutex_init(key_BITMAP_mutex, map->mutex, MY_MUTEX_INIT_FAST);
- }
- }
- else
- {
- DBUG_ASSERT(thread_safe == 0);
}
map->bitmap= buf;
@@ -200,8 +170,6 @@ void my_bitmap_free(MY_BITMAP *map)
DBUG_ENTER("my_bitmap_free");
if (map->bitmap)
{
- if (map->mutex)
- mysql_mutex_destroy(map->mutex);
my_free(map->bitmap);
map->bitmap=0;
}
@@ -247,13 +215,9 @@ my_bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit)
my_bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit)
{
- my_bool res;
DBUG_ASSERT(map->bitmap);
DBUG_ASSERT(bitmap_bit < map->n_bits);
- bitmap_lock(map);
- res= bitmap_fast_test_and_set(map, bitmap_bit);
- bitmap_unlock(map);
- return res;
+ return bitmap_fast_test_and_set(map, bitmap_bit);
}
/*
@@ -281,13 +245,9 @@ my_bool bitmap_fast_test_and_clear(MY_BITMAP *map, uint bitmap_bit)
my_bool bitmap_test_and_clear(MY_BITMAP *map, uint bitmap_bit)
{
- my_bool res;
DBUG_ASSERT(map->bitmap);
DBUG_ASSERT(bitmap_bit < map->n_bits);
- bitmap_lock(map);
- res= bitmap_fast_test_and_clear(map, bitmap_bit);
- bitmap_unlock(map);
- return res;
+ return bitmap_fast_test_and_clear(map, bitmap_bit);
}
@@ -733,24 +693,3 @@ found:
DBUG_ASSERT(0);
return MY_BIT_NONE; /* Impossible */
}
-
-
-uint bitmap_lock_set_next(MY_BITMAP *map)
-{
- uint bit_found;
- bitmap_lock(map);
- bit_found= bitmap_set_next(map);
- bitmap_unlock(map);
- return bit_found;
-}
-
-
-void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit)
-{
- bitmap_lock(map);
- DBUG_ASSERT(map->bitmap);
- DBUG_ASSERT(bitmap_bit < map->n_bits);
- bitmap_clear_bit(map, bitmap_bit);
- bitmap_unlock(map);
-}
-
diff --git a/mysys/my_default.c b/mysys/my_default.c
index cc4462a240b..ae576f7a058 100644
--- a/mysys/my_default.c
+++ b/mysys/my_default.c
@@ -466,7 +466,7 @@ int my_load_defaults(const char *conf_file, const char **groups, int *argc,
if (*argc)
memcpy(res + args.elements, *argv, *argc * sizeof(char*));
- (*argc)+= args.elements;
+ (*argc)+= (int)args.elements;
*argv= res;
(*argv)[*argc]= 0;
*(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */
@@ -602,7 +602,7 @@ static int search_default_file_with_ext(struct handle_option_ctx *ctx,
MYSQL_FILE *fp;
uint line=0;
enum { NONE, PARSE, SKIP } found_group= NONE;
- uint i;
+ size_t i;
MY_DIR *search_dir;
FILEINFO *search_file;
@@ -690,7 +690,7 @@ static int search_default_file_with_ext(struct handle_option_ctx *ctx,
if (!(search_dir= my_dir(ptr, MYF(MY_WME | MY_WANT_SORT))))
goto err;
- for (i= 0; i < (uint) search_dir->number_of_files; i++)
+ for (i= 0; i < search_dir->number_of_files; i++)
{
search_file= search_dir->dir_entry + i;
ext= fn_ext2(search_file->name);
diff --git a/mysys/my_delete.c b/mysys/my_delete.c
index d322f302ea7..25c0f4657af 100644
--- a/mysys/my_delete.c
+++ b/mysys/my_delete.c
@@ -193,7 +193,7 @@ int my_rmtree(const char *dir, myf MyFlags)
char path[FN_REFLEN];
char sep[] = { FN_LIBCHAR, 0 };
int err = 0;
- uint i;
+ size_t i;
MY_DIR *dir_info = my_dir(dir, MYF(MY_DONT_SORT | MY_WANT_STAT));
if (!dir_info)
diff --git a/mysys/my_init.c b/mysys/my_init.c
index 2b420da03be..d201d45a4ee 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -22,6 +22,9 @@
#include <m_ctype.h>
#include <signal.h>
#include <mysql/psi/mysql_stage.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#ifdef _WIN32
#ifdef _MSC_VER
#include <locale.h>
@@ -35,6 +38,10 @@ static my_bool win32_init_tcp_ip();
#define my_win_init()
#endif
+#if defined(_SC_PAGE_SIZE) && !defined(_SC_PAGESIZE)
+#define _SC_PAGESIZE _SC_PAGE_SIZE
+#endif
+
extern pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
#define SCALE_SEC 100
@@ -42,6 +49,7 @@ extern pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
my_bool my_init_done= 0;
uint mysys_usage_id= 0; /* Incremented for each my_init() */
+size_t my_system_page_size= 8192; /* Default if no sysconf() */
ulonglong my_thread_stack_size= (sizeof(void*) <= 4)? 65536: ((256-16)*1024);
@@ -79,6 +87,9 @@ my_bool my_init(void)
my_umask= 0660; /* Default umask for new files */
my_umask_dir= 0700; /* Default umask for new directories */
my_global_flags= 0;
+#ifdef _SC_PAGESIZE
+ my_system_page_size= sysconf(_SC_PAGESIZE);
+#endif
/* Default creation of new files */
if ((str= getenv("UMASK")) != 0)
diff --git a/mysys/my_lockmem.c b/mysys/my_lockmem.c
index e159502a278..a3ad7a5b76c 100644
--- a/mysys/my_lockmem.c
+++ b/mysys/my_lockmem.c
@@ -13,7 +13,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
-/* Alloc a block of locked memory */
+/* Alloc a block of locked memory (memory protected against swap) */
#include "mysys_priv.h"
#include "mysys_err.h"
@@ -33,7 +33,7 @@ LIST *mem_list;
uchar *my_malloc_lock(uint size,myf MyFlags)
{
int success;
- uint pagesize=sysconf(_SC_PAGESIZE);
+ uint pagesize= my_system_page_size;
uchar *ptr;
struct st_mem_list *element;
DBUG_ENTER("my_malloc_lock");
diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c
index befdcb0e5c3..b2cbb84984d 100644
--- a/mysys/my_malloc.c
+++ b/mysys/my_malloc.c
@@ -84,7 +84,7 @@ void *my_malloc(PSI_memory_key key, size_t size, myf my_flags)
/* We have to align size as we store MY_THREAD_SPECIFIC flag in the LSB */
size= ALIGN_SIZE(size);
- if (DBUG_EVALUATE_IF("simulate_out_of_memory", 1, 0))
+ if (DBUG_IF("simulate_out_of_memory"))
mh= NULL;
else
mh= (my_memory_header*) sf_malloc(size + HEADER_SIZE, my_flags);
diff --git a/mysys/my_uuid.c b/mysys/my_uuid.c
index 72c8fa8507d..7925f80191b 100644
--- a/mysys/my_uuid.c
+++ b/mysys/my_uuid.c
@@ -216,37 +216,6 @@ void my_uuid(uchar *to)
}
-/**
- Convert uuid to string representation
-
- @func my_uuid2str()
- @param guid uuid
- @param s Output buffer.Must be at least MY_UUID_STRING_LENGTH+1 large.
-*/
-void my_uuid2str(const uchar *guid, char *s)
-{
- int i;
- for (i=0; i < MY_UUID_SIZE; i++)
- {
- *s++= _dig_vec_lower[guid[i] >>4];
- *s++= _dig_vec_lower[guid[i] & 15];
- /* Set '-' at intervals 3, 5, 7 and 9 */
- if ((1 << i) & ((1 << 3) | (1 << 5) | (1 << 7) | (1 << 9)))
- *s++= '-';
- }
-}
-
-void my_uuid2str_oracle(const uchar *guid, char *s)
-{
- int i;
- for (i=0; i < MY_UUID_SIZE; i++)
- {
- *s++= _dig_vec_upper[guid[i] >>4];
- *s++= _dig_vec_upper[guid[i] & 15];
- }
-}
-
-
void my_uuid_end()
{
if (my_uuid_inited)
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index dd3a5ce132f..aca1c1f7731 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -332,7 +332,8 @@ int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file,
*/
pthread_mutex_lock(&THR_LOCK_mutex);
- if (!my_hash_search(mutex_root->locked_mutex, (uchar*) &mp->id, 0))
+ if (!my_hash_search(mutex_root->locked_mutex, (uchar*) &mp->id,
+ sizeof(mp->id)))
{
safe_mutex_deadlock_t *deadlock;
safe_mutex_t *mutex;
@@ -352,7 +353,8 @@ int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file,
mutex= mutex_root;
do
{
- if (my_hash_search(mp->locked_mutex, (uchar*) &mutex->id, 0))
+ if (my_hash_search(mp->locked_mutex, (uchar*) &mutex->id,
+ sizeof(mutex->id)))
{
print_deadlock_warning(mp, mutex);
/* Mark wrong usage to avoid future warnings for same error */
@@ -772,7 +774,8 @@ static my_bool remove_from_locked_mutex(safe_mutex_t *mp,
delete_mutex->id, mp->id));
found= (safe_mutex_deadlock_t *) my_hash_search(mp->locked_mutex,
- (uchar*) &delete_mutex->id, 0);
+ (uchar*) &delete_mutex->id,
+ sizeof(delete_mutex->id));
DBUG_ASSERT(found);
if (found)
{
diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c
index dd60088d534..a03f8da3009 100644
--- a/mysys/waiting_threads.c
+++ b/mysys/waiting_threads.c
@@ -598,7 +598,7 @@ static int deadlock_search(struct deadlock_arg *arg, WT_THD *blocker,
{
WT_RESOURCE *rc, *volatile *shared_ptr= &blocker->waiting_for;
WT_THD *cursor;
- uint i;
+ size_t i;
int ret= WT_OK;
DBUG_ENTER("deadlock_search");
DBUG_PRINT("wt", ("enter: thd=%s, blocker=%s, depth=%u",