MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / insert_block_index_entry

Function insert_block_index_entry

deps/concurrentqueue/concurrentqueue.h:2886–2916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2884
2885 template<AllocationMode allocMode>
2886 inline bool insert_block_index_entry(BlockIndexEntry*& idxEntry, index_t blockStartIndex)
2887 {
2888 auto localBlockIndex = blockIndex.load(std::memory_order_relaxed); // We're the only writer thread, relaxed is OK
2889 if (localBlockIndex == nullptr) {
2890 return false; // this can happen if new_block_index failed in the constructor
2891 }
2892 size_t newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1);
2893 idxEntry = localBlockIndex->index[newTail];
2894 if (idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE ||
2895 idxEntry->value.load(std::memory_order_relaxed) == nullptr) {
2896
2897 idxEntry->key.store(blockStartIndex, std::memory_order_relaxed);
2898 localBlockIndex->tail.store(newTail, std::memory_order_release);
2899 return true;
2900 }
2901
2902 // No room in the old block index, try to allocate another one!
2903 MOODYCAMEL_CONSTEXPR_IF (allocMode == CannotAlloc) {
2904 return false;
2905 }
2906 else if (!new_block_index()) {
2907 return false;
2908 }
2909 localBlockIndex = blockIndex.load(std::memory_order_relaxed);
2910 newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1);
2911 idxEntry = localBlockIndex->index[newTail];
2912 assert(idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE);
2913 idxEntry->key.store(blockStartIndex, std::memory_order_relaxed);
2914 localBlockIndex->tail.store(newTail, std::memory_order_release);
2915 return true;
2916 }
2917
2918 inline void rewind_block_index_tail()
2919 {

Callers

nothing calls this directly

Calls 2

MOODYCAMEL_CONSTEXPR_IFFunction · 0.85
new_block_indexFunction · 0.85

Tested by

no test coverage detected