void EmulatedCameraDevice::setExposureCompensation(const float ev) { ALOGV("%s", __FUNCTION__); if (!isStarted()) { ALOGW("%s: Fake camera device is not started.", __FUNCTION__); } mExposureCompensation = std::pow(2.0f, ev / GAMMA_CORRECTION); ALOGV("New exposure compensation is %f", mExposureCompensation); }
void strategyDriverTimerCallback(Timer* timer) { // enabled only if robot started if (!isStarted()) { return; } // disabled after end if (isEnd()) { return; } strategyDriverInterruptCounter++; }
void SMILTimeContainer::notifyIntervalsChanged() { if (!isStarted()) return; // Schedule updateAnimations() to be called asynchronously so multiple intervals // can change with updateAnimations() only called once at the end. if (hasPendingSynchronization()) return; cancelAnimationFrame(); scheduleWakeUp(0, SynchronizeAnimations); }
int Thread::cancel() { if (isNotOk() || !isStarted() || isDetached()) return(-1); if (isCanceled()) return(0); int status = ::pthread_cancel(state_.id_); ThreadMutexLock lock(state_.cs_); state_.canceled_ = true; setOk(status == 0); return(status); }
// Suspend the task. // This routine suspends the task. Suspension is additive: thus, tasks // can be delayed and suspended, or pended and suspended. Suspended, // delayed tasks whose delays expire remain suspended. Likewise, // suspended, pended tasks that unblock remain suspended only. OsStatus OsTaskLinux::suspend(void) { OsLock lock(mDataGuard); if (!isStarted()) return OS_TASK_NOT_STARTED; if (mSuspendCnt++ == 0) // postincrement to perform the test beforehand pthread_kill(mTaskId, SIGSTOP); return OS_SUCCESS; }
//Calls StartVM and initializes JNI structures to access ApplicationManager bool JavaInterface::StartJava() { if (jniError) return false; StartVM(); if (!isStarted()) return false; if (jniInitialized) return true; CheckAttachThread(); JNI::ReturnType ret; //share signatures const char *formatOneLong=JNI::BaseObject::getSignature(JNI::Int, 1, JNI::Object, "vdr/mhp/lang/NativeData"); const char *formatNoArguments=JNI::BaseObject::getSignature(JNI::Int, 0); if ( !( methods->initialize.SetMethod("vdr/mhp/ApplicationManager", "Initialize", JNI::Int, formatOneLong) && methods->newApplication.SetMethod("vdr/mhp/ApplicationManager", "NewApplication", JNI::Int, formatOneLong) && methods->applicationRemoved.SetMethod("vdr/mhp/ApplicationManager", "ApplicationRemoved", JNI::Int, formatOneLong) && methods->startApplication.SetMethod("vdr/mhp/ApplicationManager", "StartApplication", JNI::Int, formatOneLong) && methods->stopApplication.SetMethod("vdr/mhp/ApplicationManager", "StopApplication", JNI::Int, formatOneLong) && methods->pauseApplication.SetMethod("vdr/mhp/ApplicationManager", "PauseApplication", JNI::Int, formatOneLong) && methods->resumeApplication.SetMethod("vdr/mhp/ApplicationManager", "ResumeApplication", JNI::Int, formatOneLong) && methods->processKey.SetMethodWithArguments("vdr/mhp/ApplicationManager", "ProcessKey", JNI::Int, 1, JNI::Int) && methods->shutdown.SetMethod("vdr/mhp/ApplicationManager", "Shutdown", JNI::Int, formatNoArguments) && methods->stopApplications.SetMethod("vdr/mhp/ApplicationManager", "StopApplications", JNI::Int, formatNoArguments) && JNI::Exception::Initialize() && JNI::String::Initialize() && VdrMhpLangNativeDataImplementation::Initialize() ) ) { esyslog("Failed to initialize Java system: Cannot find method ID"); jniInitialized=false; jniError=true; return false; } delete[] formatOneLong; delete[] formatNoArguments; if (!methods->initialize.CallMethod(ret, (jobject)NativeDBData(&ApplicationInfo::Applications)) || ret.TypeInt != 0) { esyslog("Failed to initialize Java system: Cannot call method of ApplicationManager"); jniInitialized=false; jniError=true; return false; } jniInitialized = true; return true; }
void C4SoundInstance::Execute() { // Object deleted? if (pObj && !pObj->Status) ClearPointers(pObj); // initial values int32_t iVol = iVolume * 256 * Config.Sound.SoundVolume / 100, iPan = C4SoundInstance::iPan; // bound to an object? if (pObj) { int iAudibility = pObj->Audible; // apply custom falloff distance if (iFalloffDistance) { iAudibility = BoundBy<int32_t>( 100 + (iAudibility - 100) * C4AudibilityRadius / iFalloffDistance, 0, 100); } iVol = iVol * iAudibility / 100; iPan += pObj->AudiblePan; } // sound off? if (!iVol) { // stop, if started if (isStarted()) { #ifdef HAVE_LIBSDL_MIXER Mix_HaltChannel(iChannel); #endif iChannel = -1; } } else { // start if (!isStarted()) if (!CheckStart()) return; // set volume & panning #ifdef HAVE_LIBSDL_MIXER Mix_Volume(iChannel, (iVol * MIX_MAX_VOLUME) / (100 * 256)); // Mix_SetPanning(iChannel, ((100 + iPan) * 256) / 200, ((100 - iPan) * 256) // / 200); Mix_SetPanning(iChannel, BoundBy((100 - iPan) * 256 / 100, 0, 255), BoundBy((100 + iPan) * 256 / 100, 0, 255)); #endif } }
void FutureInterfaceBase::reportFinished() { //qDebug() << "BEG FutureInterfaceBase::reportFinished() this=" << this << "thread=" << QThread::currentThread() << "text=" << progressText(); QMutexLocker locker(&_mutex); OVITO_ASSERT(isStarted()); if(!isFinished()) { _state = State((_state & ~Running) | Finished); _waitCondition.wakeAll(); sendCallOut(FutureWatcher::CallOutEvent::Finished); } //qDebug() << "END FutureInterfaceBase::reportFinished() this=" << this << "thread=" << QThread::currentThread(); }
void PipeReader::start (deFile* file) { DE_ASSERT(!isStarted()); // Set to non-blocking mode. if (!deFile_setFlags(file, DE_FILE_NONBLOCKING)) XS_FAIL("Failed to set non-blocking mode"); m_file = file; de::Thread::start(); }
int Thread::join(void *&retval) { if (isNotOk() || !isStarted() || isDetached()) return(-1); if (isJoined()) return(0); retval = NULL; int status = ::pthread_join(state_.id_, &retval); ThreadMutexLock lock(state_.cs_); state_.joined_ = true; setOk(status == 0); return(status); }
void Raids::startup() { if(!isLoaded() || isStarted()) return; setLastRaidEnd(OTSYS_TIME()); checkRaidsEvent = Scheduler::getScheduler().addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL*1000, boost::bind(&Raids::checkRaids, this))); started = true; }
float MovingStats::update(float value) { avg.update(value); if (!isStarted()) _var = 0; else { float diff = value - avg.get(); _var -= avg.alpha() * (_var - sq(diff)); } return normalize(value); }
void CaseListWriter::stop (void) { if (!isStarted()) return; // Nothing to do. m_run = false; // Join thread. join(); m_file = DE_NULL; }
bool Raids::startup() { if(!isLoaded() || isStarted()) return false; setLastRaidEnd(OTSYS_TIME()); checkRaidsEvent = g_scheduler.addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL * 1000, boost::bind(&Raids::checkRaids, this))); started = true; return started; }
void PipeReader::stop (void) { if (!isStarted()) return; // Nothing to do. // Buffer must be in canceled state or otherwise stopping reader might block. DE_ASSERT(m_buf->isCanceled()); // Join thread. join(); m_file = DE_NULL; }
bool CScriptCoroutine::next() { if(!isStarted()) { Run(); wake_main.wait(); } else if(isRunning()) { wake_thread.post(); wake_main.wait(); } else return false; if(!isRunning()) return false; return true; }
bool FutureInterfaceBase::reportStarted() { //qDebug() << "BEG FutureInterfaceBase::reportStarted() this=" << this << "thread=" << QThread::currentThread() << "text=" << progressText() << "isAlreadyStarted=" << isStarted(); //qDebug() << "THREAD COUNT=" << QThreadPool::globalInstance()->activeThreadCount(); QMutexLocker locker(&_mutex); if(isStarted()) return false; // It's already started. Don't run it again. OVITO_ASSERT(!isFinished() || isRunning()); _state = State(Started | Running); sendCallOut(FutureWatcher::CallOutEvent::Started); //qDebug() << "END FutureInterfaceBase::reportStarted() this=" << this << "thread=" << QThread::currentThread() << "text=" << progressText(); return true; }
status_t EmulatedCameraDevice::stopDeliveringFrames() { ALOGV("%s", __FUNCTION__); if (!isStarted()) { ALOGW("%s: Device is not started", __FUNCTION__); return NO_ERROR; } const status_t res = stopWorkerThread(); ALOGE_IF(res != NO_ERROR, "%s: startWorkerThread failed", __FUNCTION__); return res; }
TaoClientTask::TaoClientTask(const int maxIncomingQMsgs, TaoServerTask *pTaoServerTask) : OsServerTask("TaoClient", NULL, maxIncomingQMsgs), mMutex(OsRWMutex::Q_PRIORITY) { mpConnectionSocket = 0; mpTaoServerTask = pTaoServerTask; mpAgent = NULL; initInstance(); if (!isStarted()) { start(); } }
void Effect::start() { if (isRunning() || isStarted()) { return; } mIsVisible = true; mEffectState = EFFECT_STARTED; mStartedTime = mTimer.getSeconds(); mIsChildrenRunning = false; mActualSeconds = 0.0f; mPreviousElapsed = mStartedTime; }
void Spawns::startup() { if(!isLoaded() || isStarted()) return; for(NpcList::iterator it = npcList.begin(); it != npcList.end(); ++it) g_game.placeCreature((*it), (*it)->getMasterPos(), false, true); npcList.clear(); for(SpawnList::iterator it = spawnList.begin(); it != spawnList.end(); ++it) (*it)->startup(); started = true; }
status_t EmulatedCameraDevice::startDeliveringFrames(bool one_burst) { ALOGV("%s", __FUNCTION__); if (!isStarted()) { ALOGE("%s: Device is not started", __FUNCTION__); return EINVAL; } /* Frames will be delivered from the thread routine. */ const status_t res = startWorkerThread(one_burst); ALOGE_IF(res != NO_ERROR, "%s: startWorkerThread failed", __FUNCTION__); return res; }
// Resume the task. // This routine resumes the task. The task suspension is cleared, and // the task operates in the remaining state. OsStatus OsTaskLinux::resume(void) { OsLock lock(mDataGuard); if (!isStarted()) return OS_TASK_NOT_STARTED; if (mSuspendCnt < 1) // we're already running return OS_SUCCESS; if (--mSuspendCnt == 0) // predecrement to perform the test afterward pthread_kill(mTaskId, SIGCONT); return OS_SUCCESS; }
status_t EmulatedQemuCameraDevice::startDevice(int width, int height, uint32_t pix_fmt) { ALOGV("%s", __FUNCTION__); Mutex::Autolock locker(&mObjectLock); if (!isConnected()) { ALOGE("%s: Qemu camera device '%s' is not connected.", __FUNCTION__, (const char*)mDeviceName); return EINVAL; } if (isStarted()) { ALOGW("%s: Qemu camera device '%s' is already started.", __FUNCTION__, (const char*)mDeviceName); return NO_ERROR; } status_t res = EmulatedCameraDevice::commonStartDevice(width, height, pix_fmt); if (res != NO_ERROR) { ALOGE("%s: commonStartDevice failed", __FUNCTION__); return res; } /* Allocate preview frame buffer. */ /* TODO: Watch out for preview format changes! At this point we implement * RGB32 only.*/ mPreviewFrame = new uint32_t[mTotalPixels]; if (mPreviewFrame == NULL) { ALOGE("%s: Unable to allocate %d bytes for preview frame", __FUNCTION__, mTotalPixels); return ENOMEM; } /* Start the actual camera device. */ res = mQemuClient.queryStart(mPixelFormat, mFrameWidth, mFrameHeight); if (res == NO_ERROR) { ALOGV("%s: Qemu camera device '%s' is started for %.4s[%dx%d] frames", __FUNCTION__, (const char*)mDeviceName, reinterpret_cast<const char*>(&mPixelFormat), mFrameWidth, mFrameHeight); mState = ECDS_STARTED; } else { ALOGE("%s: Unable to start device '%s' for %.4s[%dx%d] frames", __FUNCTION__, (const char*)mDeviceName, reinterpret_cast<const char*>(&pix_fmt), width, height); } return res; }
// Wait until the task is shut down and the run method has exited. // Most sub classes of OsTask should call this method in // the destructor before deleting any members which are // accessed by the run method. UtlBoolean OsTaskBase::waitUntilShutDown(int milliSecToWait) { // If task is already shut down, just return. if (isShutDown()) return TRUE; UtlString taskName = getName(); if (isStarted() || isUnInitialized()) { requestShutdown(); // ask the task to shut itself down yield(); // yield the CPU so the target task can terminate } // wait up to another nineteen seconds (20 total) for the task to terminate // printing out a console complaint every second if (isShuttingDown()) { int i; // wait up to a second for the task to terminate. for (i = 0; (i < 10) && isShuttingDown(); i++) delay(milliSecToWait/200); // wait 1/10 second for (i = 1; (i < 20) && isShuttingDown(); i++) { OsSysLog::add(FAC_KERNEL, PRI_WARNING, "Task: %s failed to terminate after %f seconds", taskName.data(), (milliSecToWait * i) / 20000.0); delay(milliSecToWait/20); } // if still no response from the task, assume it is unresponsive and // destroy the object if (isShuttingDown()) { OsSysLog::add(FAC_KERNEL, PRI_ERR, "Task: %s failed to terminate after %f seconds", taskName.data(), milliSecToWait / 1000.0); } } // Do not exit if not shut down while (isShuttingDown()) { OsSysLog::add(FAC_KERNEL, PRI_ERR, "Task: %s failed to terminate, waiting...", taskName.data()); delay(300000); } return(isShutDown()); }
void FutureInterfaceBase::waitForResult() { //qDebug() << "WAIT FOR RESULT FutureInterfaceBase::waitForResult() this=" << this << "thread=" << QThread::currentThread() << "text=" << progressText(); throwPossibleException(); QMutexLocker lock(&_mutex); if(!isRunning() && isStarted()) return; lock.unlock(); // To avoid deadlocks and reduce the number of threads used, try to // run the runnable in the current thread. tryToRunImmediately(); lock.relock(); if(!isRunning() && isStarted()) return; while(isRunning() && isResultSet() == false) _waitCondition.wait(&_mutex); throwPossibleException(); }
BOOL C4SoundInstance::CheckStart() { // already started? if (isStarted()) return TRUE; // don't bother if half the time is up and the sound is not looping if (timeGetTime() > iStarted + pEffect->Length / 2 && !fLooping) return FALSE; // do near-instances check int32_t iNearInstances = pObj ? pEffect->GetStartedInstanceCount( pObj->x, pObj->y, C4NearSoundRadius) : pEffect->GetStartedInstanceCount(); // over maximum? if (iNearInstances > iNearInstanceMax) return FALSE; // Start return Start(); }
// Destructor OsTimer::~OsTimer() { #ifndef NDEBUG CHECK_VALIDITY(this); #endif // Update members and determine whether we need to send an UPDATE_SYNC // to stop the timer or ensure that the timer task has no queued message // about this timer. UtlBoolean sendMessage = FALSE; { OsLock lock(mBSem); #ifndef NDEBUG assert(!mDeleting); // Lock out all further application methods. mDeleting = TRUE; #endif // Check if the timer needs to be stopped. if (isStarted(mApplicationState)) { sendMessage = TRUE; mApplicationState++; } // Check if there are outstanding messages that have to be waited for. if (mOutstandingMessages > 0) { sendMessage = TRUE; } // If we have to send a message, make note of it. if (sendMessage) { mOutstandingMessages++; } } // Send a message to the timer task if we need to. if (sendMessage) { OsEvent event; OsTimerMsg msg(OsTimerMsg::OS_TIMER_UPDATE_SYNC, this, &event); OsStatus res = OsTimerTask::getTimerTask()->postMessage(msg); assert(res == OS_SUCCESS); event.wait(); } // If mbManagedNotifier, free *mpNotifier. if (mbManagedNotifier) { delete mpNotifier; } }
void CurOp::setMaxTimeMicros(uint64_t maxTimeMicros) { _maxTimeMicros = maxTimeMicros; if (_maxTimeMicros == 0) { // 0 is "allow to run indefinitely". return; } // If the operation has a start time, then enable the tracker. // // If the operation has no start time yet, then ensureStarted() will take responsibility for // enabling the tracker. if (isStarted()) { _maxTimeTracker.setTimeLimit(startTime(), _maxTimeMicros); } }
void CaseListWriter::start (const char* caseList, deFile* dst) { DE_ASSERT(!isStarted()); m_file = dst; m_run = true; int caseListSize = (int)strlen(caseList)+1; m_caseList.resize(caseListSize); std::copy(caseList, caseList+caseListSize, m_caseList.begin()); // Set to non-blocking mode. if (!deFile_setFlags(m_file, DE_FILE_NONBLOCKING)) XS_FAIL("Failed to set non-blocking mode"); de::Thread::start(); }