void TimeLagFilterCore::DTCalcThread::run(){ //Disable denormalized floats _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); //Start float b, c; while(!threadShouldExit()){ if(!core.paramsChanged) wait(-1); if(threadShouldExit()) return; if(core.sampleSwapDT){ //Don't recalculate if waiting for sample to finish wait(1); //Try again soon }else{ //Copy write to calc { const ScopedWriteLock writeLock(core.ctLock); memcpy(core.ct_calc, core.ct_write, core.num_filters * sizeof (CTParams)); core.paramsChanged = false; } //Calculate filter coefficients const ScopedWriteLock writeLock(core.dtLock); for(int i=0; i<core.num_filters; ++i){ filtercalculations(core.reduced_fs, core.ct_calc[i].center, core.ct_calc[i].bw, &b, &c); core.dt_calc[i].b = b; core.dt_calc[i].c = c; } core.sampleSwapDT = true; } } }
void run() { uint32 lastTime = Time::getMillisecondCounter(); MessageManager::MessageBase::Ptr messageToSend (new CallTimersMessage()); while (! threadShouldExit()) { const uint32 now = Time::getMillisecondCounter(); if (now == lastTime) { wait (1); continue; } std::cout << "MPD: TIMER THREAD: " << now << std::endl; const int elapsed = (int) (now >= lastTime ? (now - lastTime) : (std::numeric_limits<uint32>::max() - (lastTime - now))); lastTime = now; const int timeUntilFirstTimer = getTimeUntilFirstTimer (elapsed); if (timeUntilFirstTimer <= 0) { /* If we managed to set the atomic boolean to true then send a message, this is needed as a memory barrier so the message won't be sent before callbackNeeded is set to true, but if it fails it means the message-thread changed the value from under us so at least some processing is happenening and we can just loop around and try again */ if (callbackNeeded.compareAndSetBool (1, 0)) { messageToSend->post(); /* Sometimes our message can get discarded by the OS (e.g. when running as an RTAS when the app has a modal loop), so this is how long to wait before assuming the message has been lost and trying again. */ const uint32 messageDeliveryTimeout = now + 2000; while (callbackNeeded.get() != 0) { wait (4); if (threadShouldExit()) return; if (Time::getMillisecondCounter() > messageDeliveryTimeout) break; } } } else { // don't wait for too long because running this loop also helps keep the // Time::getApproximateMillisecondTimer value stay up-to-date wait (jlimit (1, 50, timeUntilFirstTimer)); } } }
void run() { for (int i = 0; i < itemsToInstall.size(); ++i) { const ModuleList::Module* m = list.findModuleInfo (itemsToInstall[i]); jassert (m != nullptr); if (m != nullptr) { setProgress (i / (double) itemsToInstall.size()); MemoryBlock downloaded; result = download (*m, downloaded); if (result.failed()) break; if (threadShouldExit()) break; result = unzip (*m, downloaded); if (result.failed()) break; } if (threadShouldExit()) break; } }
void LR_IPC_IN::run() { while (!threadShouldExit()) { char line[256] = { '\0' }; int sizeRead = 0; bool canReadLine = true; // parse input until we have a line, then process that line while (!String(line).endsWithChar('\n') && !threadShouldExit()) { auto waitStatus = waitUntilReady(true, 0); if (waitStatus < 0) { canReadLine = false; break; } else if (waitStatus == 0) { wait(100); continue; } sizeRead += read(line + sizeRead, 1, false); } if (canReadLine) { String param(line); processLine(param); } } }
void run() { const int bufferSize = currentBufferSizeSamples; HANDLE events[2]; int numEvents = 0; if (inputDevice != 0) events [numEvents++] = inputDevice->clientEvent; if (outputDevice != 0) events [numEvents++] = outputDevice->clientEvent; const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits(); const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits(); AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32); AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32); float** const inputBuffers = ins.getArrayOfChannels(); float** const outputBuffers = outs.getArrayOfChannels(); ins.clear(); while (! threadShouldExit()) { const DWORD result = WaitForMultipleObjects (numEvents, events, true, 1000); if (result == WAIT_TIMEOUT) continue; if (threadShouldExit()) break; if (inputDevice != 0) inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this); // Make the callback.. { const ScopedLock sl (startStopLock); if (isStarted) { JUCE_TRY { callback->audioDeviceIOCallback ((const float**) inputBuffers, numInputBuffers, outputBuffers, numOutputBuffers, bufferSize); } JUCE_CATCH_EXCEPTION } else { outs.clear(); } } if (outputDevice != 0) outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this); }
void ThorUpdateThread::run() { startTimer (5000); Logger::writeToLog (T("check for updates")); updateUrl = new URL(config->getVersionUrl() + T("/thor.md5")); if (threadShouldExit()) { deleteAndZero (updateUrl); return; } String md5 = updateUrl->readEntireTextStream(); if (threadShouldExit()) { deleteAndZero (updateUrl); return; } if (!md5.isEmpty()) { File exe = File::getSpecialLocation(File::currentExecutableFile); MD5 thorMD5 (exe); if (threadShouldExit()) { deleteAndZero (updateUrl); return; } String remoteMd5 = md5.upToFirstOccurrenceOf (T(" "), false, true).toLowerCase(); String localMd5 = thorMD5.toHexString(); if (threadShouldExit()) { deleteAndZero (updateUrl); return; } if (localMd5 != remoteMd5) { AlertWindow::showMessageBox (AlertWindow::InfoIcon, T("Update"), T("New version of Thor available"), T("Ok")); } if (threadShouldExit()) { deleteAndZero (updateUrl); return; } } deleteAndZero (updateUrl); return; }
void MidiOutput::run() { while (! threadShouldExit()) { uint32 now = Time::getMillisecondCounter(); uint32 eventTime = 0; uint32 timeToWait = 500; PendingMessage* message; { const ScopedLock sl (lock); message = firstMessage; if (message != nullptr) { eventTime = (uint32) roundToInt (message->message.getTimeStamp()); if (eventTime > now + 20) { timeToWait = eventTime - (now + 20); message = nullptr; } else { firstMessage = message->next; } } } if (message != nullptr) { const ScopedPointer<PendingMessage> messageDeleter (message); if (eventTime > now) { Time::waitForMillisecondCounter (eventTime); if (threadShouldExit()) break; } if (eventTime > now - 200) sendMessageNow (message->message); } else { jassert (timeToWait < 1000 * 30); wait ((int) timeToWait); } } clearAllPendingMessages(); }
void CtrlrFileDownloader::run() { ScopedPointer <InputStream> is (fileToDownload.createInputStream (false)); const int totalLength = is->getTotalLength(); int bytesSoFar = 0; const String packageFile = CtrlrUpdateManager::getMyPackage(); if (outputFile.exists()) { outputFile.deleteFile(); outputFile.create(); } while (! (is->isExhausted())) { if (threadShouldExit()) { return; } MemoryBlock buffer(8192); const int num = is->read (buffer.getData(), 8192); if (num == 0) break; bytesSoFar += num; outputFile.appendData(buffer.getData(), buffer.getSize()); setStatusMessage ("File: " + packageFile + "\nTotal size: " + File::descriptionOfSizeInBytes (totalLength) + " Got size: " + File::descriptionOfSizeInBytes (bytesSoFar)); setProgress (bytesSoFar / (double)totalLength); } }
void run() { if (recorder != nullptr) recorder->start(); if (player != nullptr) player->start(); while (! threadShouldExit()) { if (player != nullptr) player->writeBuffer (outputBuffer, *this); if (recorder != nullptr) recorder->readNextBlock (inputBuffer, *this); const ScopedLock sl (callbackLock); if (callback != nullptr) { callback->audioDeviceIOCallback (numInputChannels > 0 ? (const float**) inputBuffer.getArrayOfChannels() : nullptr, numInputChannels, numOutputChannels > 0 ? outputBuffer.getArrayOfChannels() : nullptr, numOutputChannels, actualBufferSize); } else { outputBuffer.clear(); } } }
void BenderDataCollector::run() { float magnetData[3], accelData[3]; while (!threadShouldExit()) { { ScopedWriteLock sl(statusDataLock); benderStatus.currentTimeMillis = (double)Time::getCurrentTime().currentTimeMillis(); #ifdef LINUX if (collectNetworkData) { benderNetworkDataCollector.collect(); } XLoReadAccelerometer(accelData); XLoReadCompassRaw(magnetData); benderStatus.temperature = XLoReadTemperature(); benderStatus.magnetometerData[0] = magnetData[0]; benderStatus.magnetometerData[1] = magnetData[1]; benderStatus.magnetometerData[2] = magnetData[2]; benderStatus.accelerometerData[0] = accelData[0]; benderStatus.accelerometerData[1] = accelData[0]; benderStatus.accelerometerData[2] = accelData[0]; //_DBG ("mX: ["+String(magnetData[0],4)+"] mY: ["+String(magnetData[1],4)+"] mZ: ["+String(magnetData[2],4)+"]"); #endif } sleep (samplingInterval); } }
void MapperInterface::run() { DBG("starting mapper interface thread...\n"); while (!threadShouldExit()) { //do stuff here... int idx=0; if (myMapperOut != NULL) { myMapperOut->poll(); for (int i=0; i<kNUM_ICUBEX_SENSORS; i++) { String signame = "/sensor" + String(i); int sensorVal = mySigVals.at(idx); //note: we assume this signal exists, which may not be the case! myMapperOut->signal(signame.toStdString()).update(sensorVal); } sleep(50); //lets not be too hasty here... } } if (myMapperOut != NULL) { delete myMapperOut; } DBG("ending mapper interface thread...\n"); }
void run() { int n = 0; while (! threadShouldExit()) { int num = Random::getSystemRandom().nextInt (2000) + 1; int start1, size1, start2, size2; fifo.prepareToWrite (num, start1, size1, start2, size2); jassert (size1 >= 0 && size2 >= 0); jassert (size1 == 0 || (start1 >= 0 && start1 < fifo.getTotalSize())); jassert (size2 == 0 || (start2 >= 0 && start2 < fifo.getTotalSize())); int i; for (i = 0; i < size1; ++i) buffer [start1 + i] = n++; for (i = 0; i < size2; ++i) buffer [start2 + i] = n++; fifo.finishedWrite (size1 + size2); } }
void EdoGaduLog::run() { if (!checkSchema()) { Logger::writeToLog (T("EdoGaduLog::run schema is invalid, can't log")); return; } else { Logger::writeToLog (T("EdoGaduLog::run schema created or is valid")); } while (1) { wait (1000); if (threadShouldExit()) { flushBuffers(); return; } flushBuffers(); } }
//============================================================================== void run() { { // Allow the message thread to finish setting-up the context before using it.. MessageManagerLock mml (this); if (! mml.lockWasGained()) return; } nativeContext->makeActive(); initialiseOnThread(); #if JUCE_USE_OPENGL_SHADERS && ! JUCE_OPENGL_ES shadersAvailable = OpenGLShaderProgram::getLanguageVersion() > 0; #endif while (! threadShouldExit()) { const uint32 frameRenderStartTime = Time::getMillisecondCounter(); if (renderFrame()) waitForNextFrame (frameRenderStartTime); } shutdownOnThread(); }
void Gsp1101::run() { double prog = 0.0; AlertWindow* alertWindow; { const MessageManagerLock mml ;//(Thread::getCurrentThread()); alertWindow = LookAndFeel::getDefaultLookAndFeel() .createAlertWindow ("title", String::empty, String::empty, String::empty, String::empty, AlertWindow::NoIcon, 0, 0); alertWindow->addProgressBarComponent (prog); alertWindow->setMessage ("foo"); alertWindow->setVisible (true); } while (!threadShouldExit() && lastMidiInput_M.getSize() < 1) { wait(200); const MessageManagerLock mml (Thread::getCurrentThread()); if (! mml.lockWasGained()) // if something is trying to kill this job, the lock return; // will fail, in which case we'd better return.. prog = (prog > 1.0) ? 0.0 : prog + 0.1; yield(); //Thread::sleep(200); } const MessageManagerLock mml (Thread::getCurrentThread()); alertWindow->setVisible (false); }
void NMListener::run() { NMDevice *dev = nm_client_get_device_by_iface(nm, "wlan0"); context = g_main_context_default(); //context = g_main_context_new(); loop = g_main_loop_new(context, false); //g_main_context_invoke(context, initialize_in_context, status); g_signal_connect_swapped(nm, "notify::" NM_CLIENT_WIRELESS_ENABLED, G_CALLBACK(handle_wireless_enabled), wifiStatus); g_signal_connect_swapped(dev, "notify::" NM_DEVICE_STATE, G_CALLBACK(handle_wireless_connected), wifiStatus); g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "notify::" NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, G_CALLBACK(handle_active_access_point), wifiStatus); g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "access-point-added", G_CALLBACK(handle_changed_access_points), wifiStatus); g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "access-point-removed", G_CALLBACK(handle_changed_access_points), wifiStatus); while (!threadShouldExit()) { { const MessageManagerLock mmLock; bool dispatched = g_main_context_iteration(context, false); } wait(LIBNM_ITERATION_PERIOD); } g_main_loop_unref(loop); g_main_context_unref(context); }
void run() override { wait (15000); if (! threadShouldExit()) Process::terminate(); }
void run() { Array<int> randomValues; int lastRandomValue = 0; for (int i=1; i<=400; i++) { if ((Desktop::getMousePosition().x * Desktop::getMousePosition().y) != lastRandomValue) { randomValues.add (Desktop::getMousePosition().x * Desktop::getMousePosition().y); } lastRandomValue = Desktop::getMousePosition().x * Desktop::getMousePosition().y; setStatusMessage ("Random seed (move the mouse around to generate more): "+ STR(randomValues.size())); sleep (20); setProgress ((i / (double) 400)); if (threadShouldExit()) return; } setProgress (-1); setStatusMessage ("Generating 512 bit RSA key pair, this might take a moment"); sleep (5); RSAKey::createKeyPair (publicKey, privateKey, 512, randomValues.getRawDataPointer(), randomValues.size()); }
void run() override { setProgress (-1.0); // setting a value beyond the range 0 -> 1 will show a spinning bar.. setStatusMessage ("Preparing to do some stuff..."); wait (2000); const int thingsToDo = 10; for (int i = 0; i < thingsToDo; ++i) { // must check this as often as possible, because this is // how we know if the user's pressed 'cancel' if (threadShouldExit()) return; // this will update the progress bar on the dialog box setProgress (i / (double) thingsToDo); setStatusMessage (String (thingsToDo - i) + " things left to do..."); wait (500); } setProgress (-1.0); // setting a value beyond the range 0 -> 1 will show a spinning bar.. setStatusMessage ("Finishing off the last few bits and pieces!"); wait (2000); }
void run() { #if JUCE_LINUX { MessageManagerLock mml (this); if (! mml.lockWasGained()) return; owner.updateContext(); owner.updateContextPosition(); } #endif while (! threadShouldExit()) { const uint32 startOfRendering = Time::getMillisecondCounter(); if (! owner.performRender()) break; const int elapsed = (int) (Time::getMillisecondCounter() - startOfRendering); Thread::sleep (jmax (1, (1000 / 60) - elapsed)); } #if JUCE_LINUX owner.deleteContext(); #endif }
void SchemeThread::read() { bool more=true; bool prompt=true; String text=String::empty; CodeDocument doc; CodeDocument::Position pos(&doc,0); while (more && !threadShouldExit()) { if (prompt) { Console::getInstance()->printPrompt(); prompt=false; } std::string line=""; getline(std::cin, line); if (!text.isEmpty()) text << T("\n"); text << String(line.c_str()); int typ; doc.replaceAllContent(text); pos.setPosition(0); typ=LispSyntax::getInstance()->scanCode(doc, pos, true, ScanIDs::MoveExpressions); if (typ==ScanIDs::SCAN_LIST || typ==ScanIDs::SCAN_TOKEN || typ==ScanIDs::SCAN_STRING) break; else if (typ==ScanIDs::SCAN_UNLEVEL) break; // allow too many parens to be passed to lisp? } if (!text.isEmpty()) eval(text); }
void run() { while (! threadShouldExit()) { if (! pool.runNextJob()) wait (500); } }
void run(){ while(!threadShouldExit()){ loop(); Thread::sleep(1); // todo: sub-ms resolution sleep // yield(); // todo: yield doesn't seem to work well on } }
void TimeSliceThread::run() { int index = 0; while (! threadShouldExit()) { int timeToWait = 500; { Time nextClientTime; { const ScopedLock sl2 (listLock); index = clients.size() > 0 ? ((index + 1) % clients.size()) : 0; TimeSliceClient* const firstClient = getNextClient (index); if (firstClient != nullptr) nextClientTime = firstClient->nextCallTime; } const Time now (Time::getCurrentTime()); if (nextClientTime > now) { timeToWait = (int) jmin ((int64) 500, (nextClientTime - now).inMilliseconds()); } else { timeToWait = index == 0 ? 1 : 0; const ScopedLock sl (callbackLock); { const ScopedLock sl2 (listLock); clientBeingCalled = getNextClient (index); } if (clientBeingCalled != nullptr) { const int msUntilNextCall = clientBeingCalled->useTimeSlice(); const ScopedLock sl2 (listLock); if (msUntilNextCall >= 0) clientBeingCalled->nextCallTime += RelativeTime::milliseconds (msUntilNextCall); else clients.removeValue (clientBeingCalled); clientBeingCalled = nullptr; } } } if (timeToWait > 0) wait (timeToWait); } }
void SocketListener::run() { char buffer[1024]; while (! threadShouldExit()) { if (socket->waitUntilReady(true, -1) != 1) break; if (threadShouldExit()) break; int len = socket->read (buffer, 1024, false); if (len < 1) break; listener->ProcessPacket(buffer, len); } }
void run () { do { m_logic.periodicActivity(); wait (1000); } while (! threadShouldExit ()); }
void run() override { setProgress (-1.0); MemoryBlock zipData; result = download (zipData); if (result.wasOk() && ! threadShouldExit()) result = unzip (zipData); }
void run() override { setThreadToAudioPriority(); if (recorder != nullptr) recorder->start(); if (player != nullptr) player->start(); while (! threadShouldExit()) processBuffers(); }
void run() { initialiseJuce_GUI(); initialised = true; MessageManager::getInstance()->setCurrentThreadAsMessageThread(); while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil (250)) {} }
void TimeLagFilterCore::DlyCalcThread::run(){ //Disable denormalized floats _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); //Start float phasesum, groupsum; float a, b, center, bw, ctrsquared; float phase, group; float w, wsquared, twow, dw; int f, nw; while(!threadShouldExit()){ if(!core.paramsChangedDelay) wait(-1); if(threadShouldExit()) return; { const ScopedReadLock readLock(core.ctLock); //Calculate delays dw = core.getMaxCtr() / ResponseGraph::NUM_RESP_W; w = 0.0f; for(nw = 0; nw < ResponseGraph::NUM_RESP_W; ++nw){ phasesum = 0.0f; groupsum = 0.0f; wsquared = w * w; twow = 2.0f * w; for(f=0; f<core.num_filters; ++f){ center = core.ct_write[f].center; bw = core.ct_write[f].bw; ctrsquared = center * center; a = ctrsquared - wsquared; b = twow * bw * center; phase = -2.0f * atan2(b, a); group = -4.0f * bw * center * (ctrsquared - (core.getMaxBW() * wsquared)) / (a*a + b*b); phasesum += phase; groupsum += group; } core.phasedelay[nw] = phasesum; core.groupdelay[nw] = groupsum; w += dw; } core.paramsChangedDelay = false; } } }