| 2368 | } |
| 2369 | |
| 2370 | JavascriptThreadPool::ScopedSleeper::ScopedSleeper(JavascriptThreadPool& p_, const Identifier& id, int lineNumber_): |
| 2371 | p(p_), |
| 2372 | wasSleeping(p.isSleeping), |
| 2373 | cid(id), |
| 2374 | lineNumber(lineNumber_) |
| 2375 | { |
| 2376 | if (!p.allowSleep) |
| 2377 | return; |
| 2378 | |
| 2379 | sendMessage(true); |
| 2380 | |
| 2381 | p.isSleeping = true; |
| 2382 | p.shouldWakeUp = false; |
| 2383 | |
| 2384 | auto cThread = Thread::getCurrentThread(); |
| 2385 | std::function<bool()> shouldExit; |
| 2386 | |
| 2387 | if (cThread != nullptr) |
| 2388 | shouldExit = [cThread](){ return cThread->threadShouldExit(); }; |
| 2389 | else |
| 2390 | { |
| 2391 | auto currentThread = p.getMainController()->getKillStateHandler().getCurrentThread(); |
| 2392 | |
| 2393 | if (currentThread == MainController::KillStateHandler::TargetThread::AudioThread) |
| 2394 | { |
| 2395 | auto mc = p.getMainController(); |
| 2396 | shouldExit = [mc]() { return mc->getKillStateHandler().hasRequestedQuit(); }; |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | jassert(shouldExit); |
| 2401 | |
| 2402 | if (!shouldExit) |
| 2403 | shouldExit = []() { return true; }; |
| 2404 | |
| 2405 | while (p.allowSleep && !p.shouldWakeUp && !shouldExit()) |
| 2406 | { |
| 2407 | PendingCompilationList l; |
| 2408 | auto r = p.executeQueue(Task::ReplEvaluation, l); |
| 2409 | |
| 2410 | Thread::sleep(200); |
| 2411 | } |
| 2412 | |
| 2413 | sendMessage(false); |
| 2414 | } |
| 2415 | |
| 2416 | void JavascriptThreadPool::ScopedSleeper::sendMessage(bool on) |
| 2417 | { |
nothing calls this directly
no test coverage detected