Skip to content

Commit

Permalink
lf_hash changes, in lfind()
Browse files Browse the repository at this point in the history
casts, etc

real changes are:
* remove one retry, it is enough to check for DELETED
  after the key is read
* advance 'head' pointer when we see a dummy node to have
  shorter retries
  • Loading branch information
vuvova authored and Sergey Vojtovich committed Dec 28, 2014
1 parent c0d4e8a commit 48430e4
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions mysys/lf_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/* An element of the list */
typedef struct {
intptr volatile link; /* a pointer to the next element in a listand a flag */
intptr volatile link; /* a pointer to the next element in a list and a flag */
uint32 hashnr; /* reversed hash number, for sorting */
const uchar *key;
size_t keylen;
Expand Down Expand Up @@ -84,35 +84,34 @@ static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
cursor->curr= (LF_SLIST *)(*cursor->prev);
_lf_pin(pins, 1, cursor->curr);
} while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);

for (;;)
{
if (unlikely(!cursor->curr))
return 0; /* end of the list */

cur_hashnr= cursor->curr->hashnr;
cur_keylen= cursor->curr->keylen;
cur_key= cursor->curr->key;

do {
/* QQ: XXX or goto retry ? */
link= cursor->curr->link;
cursor->next= PTR(link);
_lf_pin(pins, 0, cursor->next);
} while (link != cursor->curr->link && LF_BACKOFF);
cur_hashnr= cursor->curr->hashnr;
cur_key= cursor->curr->key;
cur_keylen= cursor->curr->keylen;
if (*cursor->prev != (intptr)cursor->curr)
{
(void)LF_BACKOFF;
goto retry;
}

if (!DELETED(link))
{
if (cur_hashnr >= hashnr)
{
int r= 1;
if (cur_hashnr > hashnr ||
(r= my_strnncoll(cs, (uchar*) cur_key, cur_keylen, (uchar*) key,
keylen)) >= 0)
(r= my_strnncoll(cs, cur_key, cur_keylen, key, keylen)) >= 0)
return !r;
}
cursor->prev= &(cursor->curr->link);
if (!(cur_hashnr & 1)) /* dummy node */
head= (LF_SLIST **)cursor->prev;
_lf_pin(pins, 2, cursor->curr);
}
else
Expand All @@ -122,13 +121,10 @@ static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
and remove this deleted node
*/
if (my_atomic_casptr((void **) cursor->prev,
(void **)(char*) &cursor->curr, cursor->next))
(void **) &cursor->curr, cursor->next) && LF_BACKOFF)
_lf_alloc_free(pins, cursor->curr);
else
{
(void)LF_BACKOFF;
goto retry;
}
}
cursor->curr= cursor->next;
_lf_pin(pins, 1, cursor->curr);
Expand Down

0 comments on commit 48430e4

Please sign in to comment.