| 460 | } |
| 461 | |
| 462 | Dictionary::Word* Dictionary::Segment::getSpace(FB_SIZE_T len DIC_STAT_SEGMENT_PAR) |
| 463 | { |
| 464 | len = getWordLength(len); |
| 465 | |
| 466 | // get old position value |
| 467 | unsigned oldPos = position.load(std::memory_order_acquire); |
| 468 | |
| 469 | // restart loop |
| 470 | for(;;) |
| 471 | { |
| 472 | // calculate and check new position |
| 473 | unsigned newPos = oldPos + len; |
| 474 | if (newPos >= SEG_BUFFER_SIZE) |
| 475 | break; |
| 476 | |
| 477 | // try to store it safely in segment header |
| 478 | if (position.compare_exchange_weak(oldPos, newPos, std::memory_order_release, std::memory_order_acquire)) |
| 479 | { |
| 480 | return reinterpret_cast<Word*>(&buffer[oldPos]); |
| 481 | } |
| 482 | |
| 483 | #if DIC_STATS > 0 |
| 484 | ++retries; |
| 485 | #endif |
| 486 | } |
| 487 | |
| 488 | // Segment out of space |
| 489 | return nullptr; |
| 490 | } |
| 491 | |
| 492 | } // namespace Jrd |
no test coverage detected