MCPcopy Create free account
hub / github.com/KDE/kdevelop / testTryLock

Method testTryLock

kdevplatform/util/tests/test_foregroundlock.cpp:56–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56void 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"

Callers

nothing calls this directly

Calls 6

relockMethod · 0.80
reserveMethod · 0.45
push_backMethod · 0.45
startMethod · 0.45
unlockMethod · 0.45
isRunningMethod · 0.45

Tested by

no test coverage detected