| 54 | } |
| 55 | |
| 56 | void TestForegroundLock::testTryLock() |
| 57 | { |
| 58 | QFETCH(int, numThreads); |
| 59 | std::vector<std::unique_ptr<TryLockThread>> threads; |
| 60 | threads.reserve(numThreads); |
| 61 | for (int i = 0; i < numThreads; ++i) { |
| 62 | threads.push_back(std::make_unique<TryLockThread>()); |
| 63 | } |
| 64 | |
| 65 | ForegroundLock lock(true); |
| 66 | |
| 67 | for (auto& thread : threads) { |
| 68 | thread->start(); |
| 69 | } |
| 70 | |
| 71 | lock.unlock(); |
| 72 | |
| 73 | while (true) { |
| 74 | const bool running |
| 75 | = std::any_of(threads.cbegin(), threads.cend(), [](const auto& thread) { return thread->isRunning(); }); |
| 76 | |
| 77 | if (!running) { |
| 78 | break; |
| 79 | } |
| 80 | lock.relock(); |
| 81 | QThread::usleep(10); |
| 82 | lock.unlock(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | #include "moc_test_foregroundlock.cpp" |
| 87 | #include "test_foregroundlock.moc" |