mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
push for trnman review
(lockmanager still fails unit tests) BitKeeper/deleted/.del-Makefile.am~4375ae3d4de2bdf0: Delete: unittest/maria/Makefile.am configure.in: silence up configure warnings, don't generate unittest/maria/Makefile include/atomic/nolock.h: s/LOCK/LOCK_prefix/ include/atomic/x86-gcc.h: s/LOCK/LOCK_prefix/ include/atomic/x86-msvc.h: s/LOCK/LOCK_prefix/ include/lf.h: pin asserts, renames include/my_atomic.h: move cleanup include/my_bit.h: s/uint/uint32/ mysys/lf_dynarray.c: style fixes, split for() in two, remove if()s mysys/lf_hash.c: renames, minor fixes mysys/my_atomic.c: run-time assert -> compile-time assert storage/maria/Makefile.am: lockman here storage/maria/unittest/Makefile.am: new unit tests storage/maria/unittest/trnman-t.c: lots of changes storage/maria/lockman.c: many changes: second meaning of "blocker" portability: s/gettimeofday/my_getsystime/ move mutex/cond out of LOCK_OWNER - it creates a race condition that will be fixed in a separate changeset increment lm->count for every element, not only for distinct ones - because we cannot decrease it for distinct elements only :( storage/maria/lockman.h: move mutex/cond out of LOCK_OWNER storage/maria/trnman.c: move mutex/cond out of LOCK_OWNER atomic-ops to access short_trid_to_trn[] storage/maria/trnman.h: move mutex/cond out of LOCK_OWNER storage/maria/unittest/lockman-t.c: unit stress test
This commit is contained in:
@ -38,7 +38,7 @@
|
||||
void lf_dynarray_init(LF_DYNARRAY *array, uint element_size)
|
||||
{
|
||||
bzero(array, sizeof(*array));
|
||||
array->size_of_element=element_size;
|
||||
array->size_of_element= element_size;
|
||||
my_atomic_rwlock_init(&array->lock);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ static void recursive_free(void **alloc, int level)
|
||||
if (level)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < LF_DYNARRAY_LEVEL_LENGTH; i++)
|
||||
for (i= 0; i < LF_DYNARRAY_LEVEL_LENGTH; i++)
|
||||
recursive_free(alloc[i], level-1);
|
||||
my_free((void *)alloc, MYF(0));
|
||||
}
|
||||
@ -60,13 +60,13 @@ static void recursive_free(void **alloc, int level)
|
||||
void lf_dynarray_destroy(LF_DYNARRAY *array)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < LF_DYNARRAY_LEVELS; i++)
|
||||
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 int dynarray_idxes_in_level[LF_DYNARRAY_LEVELS]=
|
||||
static const int dynarray_idxes_in_prev_level[LF_DYNARRAY_LEVELS]=
|
||||
{
|
||||
0, /* +1 here to to avoid -1's below */
|
||||
LF_DYNARRAY_LEVEL_LENGTH,
|
||||
@ -77,41 +77,32 @@ static const int dynarray_idxes_in_level[LF_DYNARRAY_LEVELS]=
|
||||
|
||||
void *_lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx)
|
||||
{
|
||||
void * ptr, * volatile * ptr_ptr=0;
|
||||
void * ptr, * volatile * ptr_ptr= 0;
|
||||
int i;
|
||||
|
||||
for (i=3; i > 0; i--)
|
||||
for (i= 3; idx < dynarray_idxes_in_prev_level[i]; i--) /* no-op */;
|
||||
ptr_ptr= &array->level[i];
|
||||
idx-= dynarray_idxes_in_prev_level[i];
|
||||
for (; i > 0; i--)
|
||||
{
|
||||
if (ptr_ptr || idx >= dynarray_idxes_in_level[i])
|
||||
if (!(ptr= *ptr_ptr))
|
||||
{
|
||||
if (!ptr_ptr)
|
||||
{
|
||||
ptr_ptr=&array->level[i];
|
||||
idx-= dynarray_idxes_in_level[i];
|
||||
}
|
||||
ptr=*ptr_ptr;
|
||||
if (!ptr)
|
||||
{
|
||||
void *alloc=my_malloc(LF_DYNARRAY_LEVEL_LENGTH * sizeof(void *),
|
||||
MYF(MY_WME|MY_ZEROFILL));
|
||||
if (!alloc)
|
||||
return(NULL);
|
||||
if (my_atomic_casptr(ptr_ptr, &ptr, alloc))
|
||||
ptr= alloc;
|
||||
else
|
||||
my_free(alloc, MYF(0));
|
||||
}
|
||||
ptr_ptr=((void **)ptr) + idx / dynarray_idxes_in_level[i];
|
||||
idx%= dynarray_idxes_in_level[i];
|
||||
void *alloc= my_malloc(LF_DYNARRAY_LEVEL_LENGTH * sizeof(void *),
|
||||
MYF(MY_WME|MY_ZEROFILL));
|
||||
if (!alloc)
|
||||
return(NULL);
|
||||
if (my_atomic_casptr(ptr_ptr, &ptr, alloc))
|
||||
ptr= alloc;
|
||||
else
|
||||
my_free(alloc, MYF(0));
|
||||
}
|
||||
ptr_ptr= ((void **)ptr) + idx / dynarray_idxes_in_prev_level[i];
|
||||
idx%= dynarray_idxes_in_prev_level[i];
|
||||
}
|
||||
if (!ptr_ptr)
|
||||
ptr_ptr=&array->level[0];
|
||||
ptr=*ptr_ptr;
|
||||
if (!ptr)
|
||||
if (!(ptr= *ptr_ptr))
|
||||
{
|
||||
void *alloc, *data;
|
||||
alloc=my_malloc(LF_DYNARRAY_LEVEL_LENGTH * array->size_of_element +
|
||||
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)
|
||||
@ -123,7 +114,7 @@ void *_lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx)
|
||||
if (mod)
|
||||
data+= array->size_of_element - mod;
|
||||
}
|
||||
((void **)data)[-1]=alloc; /* free() will need the original pointer */
|
||||
((void **)data)[-1]= alloc; /* free() will need the original pointer */
|
||||
if (my_atomic_casptr(ptr_ptr, &ptr, data))
|
||||
ptr= data;
|
||||
else
|
||||
@ -134,29 +125,20 @@ void *_lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx)
|
||||
|
||||
void *_lf_dynarray_value(LF_DYNARRAY *array, uint idx)
|
||||
{
|
||||
void * ptr, * volatile * ptr_ptr=0;
|
||||
void * ptr, * volatile * ptr_ptr= 0;
|
||||
int i;
|
||||
|
||||
for (i=3; i > 0; i--)
|
||||
for (i= 3; idx < dynarray_idxes_in_prev_level[i]; i--) /* no-op */;
|
||||
ptr_ptr= &array->level[i];
|
||||
idx-= dynarray_idxes_in_prev_level[i];
|
||||
for (; i > 0; i--)
|
||||
{
|
||||
if (ptr_ptr || idx >= dynarray_idxes_in_level[i])
|
||||
{
|
||||
if (!ptr_ptr)
|
||||
{
|
||||
ptr_ptr=&array->level[i];
|
||||
idx-= dynarray_idxes_in_level[i];
|
||||
}
|
||||
ptr=*ptr_ptr;
|
||||
if (!ptr)
|
||||
return(NULL);
|
||||
ptr_ptr=((void **)ptr) + idx / dynarray_idxes_in_level[i];
|
||||
idx %= dynarray_idxes_in_level[i];
|
||||
}
|
||||
if (!(ptr= *ptr_ptr))
|
||||
return(NULL);
|
||||
ptr_ptr= ((void **)ptr) + idx / dynarray_idxes_in_prev_level[i];
|
||||
idx %= dynarray_idxes_in_prev_level[i];
|
||||
}
|
||||
if (!ptr_ptr)
|
||||
ptr_ptr=&array->level[0];
|
||||
ptr=*ptr_ptr;
|
||||
if (!ptr)
|
||||
if (!(ptr= *ptr_ptr))
|
||||
return(NULL);
|
||||
return ptr + array->size_of_element * idx;
|
||||
}
|
||||
@ -169,8 +151,8 @@ static int recursive_iterate(LF_DYNARRAY *array, void *ptr, int level,
|
||||
return 0;
|
||||
if (!level)
|
||||
return func(ptr, arg);
|
||||
for (i=0; i < LF_DYNARRAY_LEVEL_LENGTH; i++)
|
||||
if ((res=recursive_iterate(array, ((void **)ptr)[i], level-1, func, arg)))
|
||||
for (i= 0; i < LF_DYNARRAY_LEVEL_LENGTH; i++)
|
||||
if ((res= recursive_iterate(array, ((void **)ptr)[i], level-1, func, arg)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
@ -178,8 +160,8 @@ static int recursive_iterate(LF_DYNARRAY *array, void *ptr, int level,
|
||||
int _lf_dynarray_iterate(LF_DYNARRAY *array, lf_dynarray_func func, void *arg)
|
||||
{
|
||||
int i, res;
|
||||
for (i=0; i < LF_DYNARRAY_LEVELS; i++)
|
||||
if ((res=recursive_iterate(array, array->level[i], i, func, arg)))
|
||||
for (i= 0; i < LF_DYNARRAY_LEVELS; i++)
|
||||
if ((res= recursive_iterate(array, array->level[i], i, func, arg)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user