MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / thread

Method thread

tests/relacy/spmchash.cpp:202–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200 }
201
202 void thread(unsigned int tid)
203 {
204 if (tid == 0) {
205 // Producer
206 for (int i = 0; i != NUM_VALUES; ++i) {
207 hash->insert(i, &values[i]);
208 useCounts[i].store(ThreadCount / 2, std::memory_order_release);
209 }
210 }
211 else {
212 // Consumer
213 for (int i = 0; i != NUM_VALUES; ++i) {
214 auto useCount = useCounts[i].fetch_add(-1, std::memory_order_acquire);
215 auto val = hash->find(i);
216 bool isRemoved = removed[i].load(std::memory_order_relaxed);
217 auto current = useCounts[i].fetch_add(0, std::memory_order_release);
218 if (useCount > 0 && (current > 0 || current == 0 && useCount == 1)) {
219 RL_ASSERT(val != nullptr && *val == i && !isRemoved);
220 }
221 if (useCount == 1) {
222 val = hash->remove(i);
223 RL_ASSERT(val != nullptr && *val == i && !removed[i].load(std::memory_order_relaxed));
224 removed[i].store(true, std::memory_order_release);
225 }
226 }
227 }
228 }
229
230 void after()
231 {

Callers

nothing calls this directly

Calls 6

insertMethod · 0.45
storeMethod · 0.45
fetch_addMethod · 0.45
findMethod · 0.45
loadMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected