A helper struct used by queueing tests which use multiple threads.
| 2168 | |
| 2169 | // A helper struct used by queueing tests which use multiple threads. |
| 2170 | struct QueueTestThreadState { |
| 2171 | QueueTestThreadState(int threadId, int toProduce) : threadId(threadId), toProduce(toProduce) {} |
| 2172 | int threadId; |
| 2173 | THREAD_HANDLE handle; |
| 2174 | int toProduce; |
| 2175 | int produced = 0; |
| 2176 | Promise<Void> doneProducing; |
| 2177 | int consumed = 0; |
| 2178 | |
| 2179 | static int valueToThreadId(int value) { return value >> 20; } |
| 2180 | int elementValue(int index) { return index + (threadId << 20); } |
| 2181 | int nextProduced() { return elementValue(produced++); } |
| 2182 | int nextConsumed() { return elementValue(consumed++); } |
| 2183 | void checkDone() { |
| 2184 | ASSERT_EQ(produced, toProduce); |
| 2185 | ASSERT_EQ(consumed, produced); |
| 2186 | } |
| 2187 | }; |
| 2188 | |
| 2189 | TEST_CASE("/flow/Net2/ThreadSafeQueue/Threaded") { |
| 2190 | // Uses ThreadSafeQueue from multiple threads. Verifies that all pushed elements are popped, maintaining the |