MCPcopy Create free account
hub / github.com/apple/foundationdb / copy

Method copy

flow/WriteOnlySet.actor.cpp:108–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107template <class T, class IndexType, IndexType CAPACITY>
108std::vector<Reference<T>> WriteOnlySet<T, IndexType, CAPACITY>::copy() {
109 std::vector<Reference<T>> result;
110 for (int i = 0; i < CAPACITY; ++i) {
111 auto ptr = _set[i].load();
112 if (ptr) {
113 ASSERT((ptr & LOCK) == 0); // if we lock something we need to immediately unlock after we're done copying
114 // We attempt lock so this won't get deleted. We will try this only once, if the other thread removed the
115 // object from the set between the previews lines and now, we just won't make it part of the result.
116 if (_set[i].compare_exchange_strong(ptr, ptr | LOCK)) {
117 T* entry = reinterpret_cast<T*>(ptr);
118 ptr |= LOCK;
119 entry->addref();
120 // we try to unlock now. If this element was removed while we incremented the refcount, the element will
121 // end up in the freeList, so we will decrement later.
122 _set[i].compare_exchange_strong(ptr, ptr ^ LOCK);
123 result.push_back(Reference(entry));
124 }
125 }
126 }
127 // after we're done we need to clean up all objects that contented on a lock. This won't be perfect (as some thread
128 // might not yet added the object to the free list), but whatever we don't get now we'll clean up in the next
129 // iteration
130 freeList.consume_all([](auto toClean) { toClean->delref(); });
131 return result;
132}
133
134template <class T, class IndexType>
135WriteOnlyVariable<T, IndexType>::WriteOnlyVariable() : WriteOnlySet<T, IndexType, 1>() {}

Callers 15

testCopierFunction · 0.45
init_resultMethod · 0.45
runFunction · 0.45
fdbcli_tests.pyFile · 0.45
wrapperFunction · 0.45
__init__Method · 0.45
_mergeMethod · 0.45
run_c_api_testMethod · 0.45
run_c_unit_testsMethod · 0.45
run_c_shim_lib_testerMethod · 0.45
cluster_wiggleMethod · 0.45

Calls 5

ReferenceClass · 0.85
loadMethod · 0.45
addrefMethod · 0.45
push_backMethod · 0.45
delrefMethod · 0.45

Tested by 4

__init__Method · 0.36
run_c_api_testMethod · 0.36
run_c_unit_testsMethod · 0.36
run_c_shim_lib_testerMethod · 0.36