summaryrefslogtreecommitdiff
path: root/mysys/my_alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/my_alloc.c')
-rw-r--r--mysys/my_alloc.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 1054db6cee4..6c8a73df4a7 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -22,6 +22,10 @@
#undef EXTRA_DEBUG
#define EXTRA_DEBUG
+/* data packed in MEM_ROOT -> min_malloc */
+
+#define MALLOC_FLAG(A) ((A & 1) ? MY_THREAD_SPECIFIC : 0)
+
/*
Initialize memory root
@@ -34,6 +38,7 @@
should be no less than ALLOC_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
DESCRIPTION
This function prepares memory root for further use, sets initial size of
@@ -41,17 +46,24 @@
Altough 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(MEM_ROOT *mem_root, size_t block_size,
- size_t pre_alloc_size __attribute__((unused)))
+ size_t pre_alloc_size __attribute__((unused)),
+ myf my_flags)
{
DBUG_ENTER("init_alloc_root");
DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root));
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;
+ mem_root->block_size= (block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1;
+ if (test(my_flags & MY_THREAD_SPECIFIC))
+ mem_root->block_size|= 1;
+
mem_root->error_handler= 0;
mem_root->block_num= 4; /* We shift this with >>2 */
mem_root->first_block_usage= 0;
@@ -61,7 +73,7 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
{
if ((mem_root->free= mem_root->pre_alloc=
(USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
- MYF(0))))
+ MYF(my_flags))))
{
mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
mem_root->free->left= pre_alloc_size;
@@ -72,7 +84,6 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
DBUG_VOID_RETURN;
}
-
/*
SYNOPSIS
reset_root_defaults()
@@ -95,7 +106,8 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
{
DBUG_ASSERT(alloc_root_inited(mem_root));
- mem_root->block_size= block_size - ALLOC_ROOT_MIN_BLOCK_SIZE;
+ mem_root->block_size= (((block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1) |
+ (mem_root->block_size & 1));
#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
{
@@ -126,7 +138,9 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
prev= &mem->next;
}
/* Allocate new prealloc block and add it to the end of free list */
- if ((mem= (USED_MEM *) my_malloc(size, MYF(0))))
+ if ((mem= (USED_MEM *) my_malloc(size,
+ MYF(MALLOC_FLAG(mem_root->
+ block_size)))))
{
mem->size= size;
mem->left= pre_alloc_size;
@@ -163,7 +177,9 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
});
length+=ALIGN_SIZE(sizeof(USED_MEM));
- if (!(next = (USED_MEM*) my_malloc(length,MYF(MY_WME | ME_FATALERROR))))
+ if (!(next = (USED_MEM*) my_malloc(length,
+ MYF(MY_WME | ME_FATALERROR |
+ MALLOC_FLAG(mem_root->block_size)))))
{
if (mem_root->error_handler)
(*mem_root->error_handler)();
@@ -210,11 +226,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
}
if (! next)
{ /* Time to alloc new block */
- block_size= mem_root->block_size * (mem_root->block_num >> 2);
+ block_size= (mem_root->block_size & ~1) * (mem_root->block_num >> 2);
get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
get_size= max(get_size, block_size);
- if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | ME_FATALERROR))))
+ if (!(next = (USED_MEM*) my_malloc(get_size,
+ MYF(MY_WME | ME_FATALERROR |
+ MALLOC_FLAG(mem_root->
+ block_size)))))
{
if (mem_root->error_handler)
(*mem_root->error_handler)();