Commit 48430e46 authored by Sergei Golubchik's avatar Sergei Golubchik Committed by Sergey Vojtovich

lf_hash changes, in lfind()

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
parent c0d4e8a3
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
/* An element of the list */ /* An element of the list */
typedef struct { 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 */ uint32 hashnr; /* reversed hash number, for sorting */
const uchar *key; const uchar *key;
size_t keylen; size_t keylen;
...@@ -84,35 +84,34 @@ retry: ...@@ -84,35 +84,34 @@ retry:
cursor->curr= (LF_SLIST *)(*cursor->prev); cursor->curr= (LF_SLIST *)(*cursor->prev);
_lf_pin(pins, 1, cursor->curr); _lf_pin(pins, 1, cursor->curr);
} while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF); } while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);
for (;;) for (;;)
{ {
if (unlikely(!cursor->curr)) if (unlikely(!cursor->curr))
return 0; /* end of the list */ return 0; /* end of the list */
cur_hashnr= cursor->curr->hashnr;
cur_keylen= cursor->curr->keylen;
cur_key= cursor->curr->key;
do { do {
/* QQ: XXX or goto retry ? */
link= cursor->curr->link; link= cursor->curr->link;
cursor->next= PTR(link); cursor->next= PTR(link);
_lf_pin(pins, 0, cursor->next); _lf_pin(pins, 0, cursor->next);
} while (link != cursor->curr->link && LF_BACKOFF); } 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 (!DELETED(link))
{ {
if (cur_hashnr >= hashnr) if (cur_hashnr >= hashnr)
{ {
int r= 1; int r= 1;
if (cur_hashnr > hashnr || if (cur_hashnr > hashnr ||
(r= my_strnncoll(cs, (uchar*) cur_key, cur_keylen, (uchar*) key, (r= my_strnncoll(cs, cur_key, cur_keylen, key, keylen)) >= 0)
keylen)) >= 0)
return !r; return !r;
} }
cursor->prev= &(cursor->curr->link); cursor->prev= &(cursor->curr->link);
if (!(cur_hashnr & 1)) /* dummy node */
head= (LF_SLIST **)cursor->prev;
_lf_pin(pins, 2, cursor->curr); _lf_pin(pins, 2, cursor->curr);
} }
else else
...@@ -122,14 +121,11 @@ retry: ...@@ -122,14 +121,11 @@ retry:
and remove this deleted node and remove this deleted node
*/ */
if (my_atomic_casptr((void **) cursor->prev, 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); _lf_alloc_free(pins, cursor->curr);
else else
{
(void)LF_BACKOFF;
goto retry; goto retry;
} }
}
cursor->curr= cursor->next; cursor->curr= cursor->next;
_lf_pin(pins, 1, cursor->curr); _lf_pin(pins, 1, cursor->curr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment