From 915cebdd53fe5071dc9443a236a798764f504c22 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Nov 2006 15:40:08 +0100 Subject: post-review fixes. tablockman: fixed a bug in finding a blocker lock mysys/my_getsystime.c: this is no longer true storage/maria/lockman.h: post-review fixes storage/maria/tablockman.h: post-review fixes storage/maria/unittest/lockman-t.c: post-review fixes storage/maria/unittest/lockman1-t.c: post-review fixes storage/maria/unittest/lockman2-t.c: post-review fixes include/my_atomic.h: moved intptr definition to my_global.h storage/maria/tablockman.c: post-review fixes BUILD/SETUP.sh: add -DMY_LF_EXTRA_DEBUG to debug builds include/atomic/nolock.h: suppress warning include/my_global.h: suppress warning mysys/lf_alloc-pin.c: post-review fixes mysys/lf_dynarray.c: post-review fixes mysys/lf_hash.c: post-review fixes storage/maria/trnman.c: suppress warning include/lf.h: post-review fix --- mysys/lf_dynarray.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'mysys/lf_dynarray.c') diff --git a/mysys/lf_dynarray.c b/mysys/lf_dynarray.c index d63af91813e..c6dd654bf03 100644 --- a/mysys/lf_dynarray.c +++ b/mysys/lf_dynarray.c @@ -19,9 +19,9 @@ (so no pointer into the array may ever become invalid). Memory is allocated in non-contiguous chunks. - This data structure is not space efficient for sparce arrays. + This data structure is not space efficient for sparse arrays. - The number of elements is limited to 2^16 + The number of elements is limited to 4311810304 Every element is aligned to sizeof(element) boundary (to avoid false sharing if element is big enough). @@ -49,7 +49,8 @@ void lf_dynarray_init(LF_DYNARRAY *array, uint element_size) static void recursive_free(void **alloc, int level) { - if (!alloc) return; + if (!alloc) + return; if (level) { @@ -68,10 +69,9 @@ void lf_dynarray_destroy(LF_DYNARRAY *array) for (i= 0; i < LF_DYNARRAY_LEVELS; i++) recursive_free(array->level[i], i); my_atomic_rwlock_destroy(&array->lock); - bzero(array, sizeof(*array)); } -static const long dynarray_idxes_in_prev_level[LF_DYNARRAY_LEVELS]= +static const ulong dynarray_idxes_in_prev_levels[LF_DYNARRAY_LEVELS]= { 0, /* +1 here to to avoid -1's below */ LF_DYNARRAY_LEVEL_LENGTH, @@ -82,6 +82,15 @@ static const long dynarray_idxes_in_prev_level[LF_DYNARRAY_LEVELS]= LF_DYNARRAY_LEVEL_LENGTH + LF_DYNARRAY_LEVEL_LENGTH }; +static const ulong dynarray_idxes_in_prev_level[LF_DYNARRAY_LEVELS]= +{ + 0, /* +1 here to to avoid -1's below */ + LF_DYNARRAY_LEVEL_LENGTH, + LF_DYNARRAY_LEVEL_LENGTH * LF_DYNARRAY_LEVEL_LENGTH, + LF_DYNARRAY_LEVEL_LENGTH * LF_DYNARRAY_LEVEL_LENGTH * + LF_DYNARRAY_LEVEL_LENGTH, +}; + /* Returns a valid lvalue pointer to the element number 'idx'. Allocates memory if necessary. @@ -91,16 +100,17 @@ void *_lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx) void * ptr, * volatile * ptr_ptr= 0; int i; - for (i= 3; idx < dynarray_idxes_in_prev_level[i]; i--) /* no-op */; + for (i= LF_DYNARRAY_LEVELS-1; idx < dynarray_idxes_in_prev_levels[i]; i--) + /* no-op */; ptr_ptr= &array->level[i]; - idx-= dynarray_idxes_in_prev_level[i]; + idx-= dynarray_idxes_in_prev_levels[i]; for (; i > 0; i--) { if (!(ptr= *ptr_ptr)) { void *alloc= my_malloc(LF_DYNARRAY_LEVEL_LENGTH * sizeof(void *), - MYF(MY_WME|MY_ZEROFILL)); - if (!alloc) + MYF(MY_WME|MY_ZEROFILL)); + if (unlikely(!alloc)) return(NULL); if (my_atomic_casptr(ptr_ptr, &ptr, alloc)) ptr= alloc; @@ -116,7 +126,7 @@ void *_lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx) alloc= my_malloc(LF_DYNARRAY_LEVEL_LENGTH * array->size_of_element + max(array->size_of_element, sizeof(void *)), MYF(MY_WME|MY_ZEROFILL)); - if (!alloc) + if (unlikely(!alloc)) return(NULL); /* reserve the space for free() address */ data= alloc + sizeof(void *); @@ -143,9 +153,10 @@ void *_lf_dynarray_value(LF_DYNARRAY *array, uint idx) void * ptr, * volatile * ptr_ptr= 0; int i; - for (i= 3; idx < dynarray_idxes_in_prev_level[i]; i--) /* no-op */; + for (i= LF_DYNARRAY_LEVELS-1; idx < dynarray_idxes_in_prev_levels[i]; i--) + /* no-op */; ptr_ptr= &array->level[i]; - idx-= dynarray_idxes_in_prev_level[i]; + idx-= dynarray_idxes_in_prev_levels[i]; for (; i > 0; i--) { if (!(ptr= *ptr_ptr)) -- cgit v1.2.1