@ -43,7 +43,7 @@ const int LF_HASH_OVERHEAD= sizeof(LF_SLIST);
/*
a structure to pass the context ( pointers two the three successive elements
in a list ) from lfind to linsert / ldelete
in a list ) from l_ find to l_ insert / l_ delete
*/
typedef struct {
intptr volatile * prev ;
@ -70,7 +70,7 @@ typedef struct {
cursor is positioned in either case
pins [ 0. .2 ] are used , they are NOT removed on return
*/
static int lfind ( LF_SLIST * volatile * head , CHARSET_INFO * cs , uint32 hashnr ,
static int l_ find ( LF_SLIST * volatile * head , CHARSET_INFO * cs , uint32 hashnr ,
const uchar * key , uint keylen , CURSOR * cursor , LF_PINS * pins )
{
uint32 cur_hashnr ;
@ -138,7 +138,7 @@ retry:
/*
DESCRIPTION
insert a ' node ' in the list that starts from ' head ' in the correct
position ( as found by lfind )
position ( as found by l_ find )
RETURN
0 - inserted
@ -148,7 +148,7 @@ retry:
it uses pins [ 0. .2 ] , on return all pins are removed .
if there ' re nodes with the same key value , a new node is added before them .
*/
static LF_SLIST * linsert ( LF_SLIST * volatile * head , CHARSET_INFO * cs ,
static LF_SLIST * l_ insert ( LF_SLIST * volatile * head , CHARSET_INFO * cs ,
LF_SLIST * node , LF_PINS * pins , uint flags )
{
CURSOR cursor ;
@ -156,7 +156,7 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
for ( ; ; )
{
if ( lfind ( head , cs , node - > hashnr , node - > key , node - > keylen ,
if ( l_ find ( head , cs , node - > hashnr , node - > key , node - > keylen ,
& cursor , pins ) & &
( flags & LF_HASH_UNIQUE ) )
{
@ -200,7 +200,7 @@ static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
NOTE
it uses pins [ 0. .2 ] , on return all pins are removed .
*/
static int ldelete ( LF_SLIST * volatile * head , CHARSET_INFO * cs , uint32 hashnr ,
static int l_ delete ( LF_SLIST * volatile * head , CHARSET_INFO * cs , uint32 hashnr ,
const uchar * key , uint keylen , LF_PINS * pins )
{
CURSOR cursor ;
@ -208,7 +208,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
for ( ; ; )
{
if ( ! lfind ( head , cs , hashnr , key , keylen , & cursor , pins ) )
if ( ! l_ find ( head , cs , hashnr , key , keylen , & cursor , pins ) )
{
res = 1 ; /* not found */
break ;
@ -232,7 +232,7 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
( to ensure the number of " set DELETED flag " actions
is equal to the number of " remove from the list " actions )
*/
lfind ( head , cs , hashnr , key , keylen , & cursor , pins ) ;
l_ find ( head , cs , hashnr , key , keylen , & cursor , pins ) ;
}
res = 0 ;
break ;
@ -258,12 +258,12 @@ static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
it uses pins [ 0. .2 ] , on return the pin [ 2 ] keeps the node found
all other pins are removed .
*/
static LF_SLIST * lsearch ( LF_SLIST * volatile * head , CHARSET_INFO * cs ,
static LF_SLIST * l_ search ( LF_SLIST * volatile * head , CHARSET_INFO * cs ,
uint32 hashnr , const uchar * key , uint keylen ,
LF_PINS * pins )
{
CURSOR cursor ;
int res = lfind ( head , cs , hashnr , key , keylen , & cursor , pins ) ;
int res = l_ find ( head , cs , hashnr , key , keylen , & cursor , pins ) ;
if ( res )
_lf_pin ( pins , 2 , cursor . curr ) ;
else
@ -363,7 +363,7 @@ void lf_hash_destroy(LF_HASH *hash)
- 1 - out of memory
NOTE
see linsert ( ) for pin usage notes
see l_ insert ( ) for pin usage notes
*/
int lf_hash_insert ( LF_HASH * hash , LF_PINS * pins , const void * data )
{
@ -384,7 +384,7 @@ int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
if ( * el = = NULL & & unlikely ( initialize_bucket ( hash , el , bucket , pins ) ) )
return - 1 ;
node - > hashnr = my_reverse_bits ( hashnr ) | 1 ; /* normal node */
if ( linsert ( el , hash - > charset , node , pins , hash - > flags ) )
if ( l_ insert ( el , hash - > charset , node , pins , hash - > flags ) )
{
_lf_alloc_free ( pins , node ) ;
lf_rwunlock_by_pins ( pins ) ;
@ -407,7 +407,7 @@ int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
1 - didn ' t ( not found )
- 1 - out of memory
NOTE
see ldelete ( ) for pin usage notes
see l_ delete ( ) for pin usage notes
*/
int lf_hash_delete ( LF_HASH * hash , LF_PINS * pins , const void * key , uint keylen )
{
@ -427,7 +427,7 @@ int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
*/
if ( * el = = NULL & & unlikely ( initialize_bucket ( hash , el , bucket , pins ) ) )
return - 1 ;
if ( ldelete ( el , hash - > charset , my_reverse_bits ( hashnr ) | 1 ,
if ( l_ delete ( el , hash - > charset , my_reverse_bits ( hashnr ) | 1 ,
( uchar * ) key , keylen , pins ) )
{
lf_rwunlock_by_pins ( pins ) ;
@ -446,7 +446,7 @@ int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
MY_ERRPTR if OOM
NOTE
see lsearch ( ) for pin usage notes
see l_ search ( ) for pin usage notes
*/
void * lf_hash_search ( LF_HASH * hash , LF_PINS * pins , const void * key , uint keylen )
{
@ -460,7 +460,7 @@ void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
return MY_ERRPTR ;
if ( * el = = NULL & & unlikely ( initialize_bucket ( hash , el , bucket , pins ) ) )
return MY_ERRPTR ;
found = lsearch ( el , hash - > charset , my_reverse_bits ( hashnr ) | 1 ,
found = l_ search ( el , hash - > charset , my_reverse_bits ( hashnr ) | 1 ,
( uchar * ) key , keylen , pins ) ;
lf_rwunlock_by_pins ( pins ) ;
return found ? found + 1 : 0 ;
@ -488,16 +488,16 @@ static int initialize_bucket(LF_HASH *hash, LF_SLIST * volatile *node,
dummy - > hashnr = my_reverse_bits ( bucket ) | 0 ; /* dummy node */
dummy - > key = dummy_key ;
dummy - > keylen = 0 ;
if ( ( cur = linsert ( el , hash - > charset , dummy , pins , LF_HASH_UNIQUE ) ) )
if ( ( cur = l_ insert ( el , hash - > charset , dummy , pins , LF_HASH_UNIQUE ) ) )
{
my_free ( dummy ) ;
dummy = cur ;
}
my_atomic_casptr ( ( void * * ) node , ( void * * ) ( char * ) & tmp , dummy ) ;
/*
note that if the CAS above failed ( after linsert ( ) succeeded ) ,
it would mean that some other thread has executed linsert ( ) for
the same dummy node , its linsert ( ) failed , it picked up our
note that if the CAS above failed ( after l_ insert ( ) succeeded ) ,
it would mean that some other thread has executed l_ insert ( ) for
the same dummy node , its l_ insert ( ) failed , it picked up our
dummy node ( in " dummy= cur " ) and executed the same CAS as above .
Which means that even if CAS above failed we don ' t need to retry ,
and we should not free ( dummy ) - there ' s no memory leak here