DESCRIPTION insert a 'node' in the list that starts from 'head' in the correct position (as found by lfind) RETURN 0 - inserted not 0 - a pointer to a duplicate (not pinned and thus unusable) NOTE 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. */
| 151 | if there're nodes with the same key value, a new node is added before them. |
| 152 | */ |
| 153 | static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs, |
| 154 | LF_SLIST *node, LF_PINS *pins, uint flags) |
| 155 | { |
| 156 | CURSOR cursor; |
| 157 | int res; |
| 158 | |
| 159 | for (;;) |
| 160 | { |
| 161 | if (lfind(head, cs, node->hashnr, node->key, node->keylen, |
| 162 | &cursor, pins) && |
| 163 | (flags & LF_HASH_UNIQUE)) |
| 164 | { |
| 165 | res= 0; /* duplicate found */ |
| 166 | break; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | node->link= (intptr)cursor.curr; |
| 171 | DBUG_ASSERT(node->link != (intptr)node); /* no circular references */ |
| 172 | DBUG_ASSERT(cursor.prev != &node->link); /* no circular references */ |
| 173 | if (my_atomic_casptr((void **)cursor.prev, (void **)&cursor.curr, node)) |
| 174 | { |
| 175 | res= 1; /* inserted ok */ |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | _lf_unpin(pins, 0); |
| 181 | _lf_unpin(pins, 1); |
| 182 | _lf_unpin(pins, 2); |
| 183 | /* |
| 184 | Note that cursor.curr is not pinned here and the pointer is unreliable, |
| 185 | the object may dissapear anytime. But if it points to a dummy node, the |
| 186 | pointer is safe, because dummy nodes are never freed - initialize_bucket() |
| 187 | uses this fact. |
| 188 | */ |
| 189 | return res ? 0 : cursor.curr; |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | DESCRIPTION |
no test coverage detected