MCPcopy Create free account
hub / github.com/christophhart/HISE / ScopedSleeper

Method ScopedSleeper

hi_scripting/scripting/ScriptProcessor.cpp:2370–2414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2368}
2369
2370JavascriptThreadPool::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
2416void JavascriptThreadPool::ScopedSleeper::sendMessage(bool on)
2417{

Callers

nothing calls this directly

Calls 6

shouldExitFunction · 0.85
hasRequestedQuitMethod · 0.80
executeQueueMethod · 0.80
threadShouldExitMethod · 0.45
getCurrentThreadMethod · 0.45
getMainControllerMethod · 0.45

Tested by

no test coverage detected