MCPcopy Create free account
hub / github.com/axmolengine/axmol / insert_block_index_entry

Function insert_block_index_entry

3rdparty/concurrentqueue/concurrentqueue.h:2901–2932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2899
2900 template<AllocationMode allocMode>
2901 inline bool insert_block_index_entry(BlockIndexEntry*& idxEntry, index_t blockStartIndex)
2902 {
2903 auto localBlockIndex = blockIndex.load(std::memory_order_relaxed); // We're the only writer thread, relaxed is OK
2904 if (localBlockIndex == nullptr) {
2905 return false; // this can happen if new_block_index failed in the constructor
2906 }
2907 size_t newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1);
2908 idxEntry = localBlockIndex->index[newTail];
2909 if (idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE ||
2910 idxEntry->value.load(std::memory_order_relaxed) == nullptr) {
2911
2912 idxEntry->key.store(blockStartIndex, std::memory_order_relaxed);
2913 localBlockIndex->tail.store(newTail, std::memory_order_release);
2914 return true;
2915 }
2916
2917 // No room in the old block index, try to allocate another one!
2918 MOODYCAMEL_CONSTEXPR_IF (allocMode == CannotAlloc) {
2919 return false;
2920 }
2921 else if (!new_block_index()) {
2922 return false;
2923 }
2924 else {
2925 localBlockIndex = blockIndex.load(std::memory_order_relaxed);
2926 newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1);
2927 idxEntry = localBlockIndex->index[newTail];
2928 assert(idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE);
2929 idxEntry->key.store(blockStartIndex, std::memory_order_relaxed);
2930 localBlockIndex->tail.store(newTail, std::memory_order_release);
2931 return true;
2932 }
2933 }
2934
2935 inline void rewind_block_index_tail()

Callers

nothing calls this directly

Calls 4

MOODYCAMEL_CONSTEXPR_IFFunction · 0.85
new_block_indexFunction · 0.85
storeMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected